findepi commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1845129045
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType,
rhs_type: &DataType) -> Option<D
}
}
+macro_rules! coerce_list_children {
+ ($LHS_TYPE:expr, $RHS_TYPE:expr) => {
+ Arc::new(Arc::unwrap_or_clone(Arc::clone($LHS_TYPE)).with_data_type(
+ comparison_coercion($LHS_TYPE.data_type(), $RHS_TYPE.data_type())?,
+ ))
+ };
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType>
{
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
- (List(_), LargeList(_)) => Some(rhs_type.clone()),
- (LargeList(_), LargeList(_)) => Some(lhs_type.clone()),
- (List(_), FixedSizeList(_, _)) => Some(lhs_type.clone()),
- (FixedSizeList(_, _), List(_)) => Some(rhs_type.clone()),
+ (List(lhs_field), List(rhs_field))
+ | (List(lhs_field), FixedSizeList(rhs_field, _))
+ | (FixedSizeList(lhs_field, _), List(rhs_field)) => {
+ Some(List(coerce_list_children!(lhs_field, rhs_field)))
+ }
+
+ (LargeList(lhs_field), List(rhs_field))
+ | (List(lhs_field), LargeList(rhs_field))
+ | (LargeList(lhs_field), LargeList(rhs_field))
+ | (LargeList(lhs_field), FixedSizeList(rhs_field, _))
+ | (FixedSizeList(lhs_field, _), LargeList(rhs_field)) => {
+ Some(LargeList(coerce_list_children!(lhs_field, rhs_field)))
Review Comment:
nit: handle large list first
nit2 the pattern will be simpler if you put `|`s inside the `(..., ...)`
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType,
rhs_type: &DataType) -> Option<D
}
}
+macro_rules! coerce_list_children {
+ ($LHS_TYPE:expr, $RHS_TYPE:expr) => {
+ Arc::new(Arc::unwrap_or_clone(Arc::clone($LHS_TYPE)).with_data_type(
+ comparison_coercion($LHS_TYPE.data_type(), $RHS_TYPE.data_type())?,
+ ))
+ };
+}
Review Comment:
Can this be an ordinary function?
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1138,44 @@ fn numeric_string_coercion(lhs_type: &DataType,
rhs_type: &DataType) -> Option<D
}
}
+macro_rules! coerce_list_children {
+ ($LHS_TYPE:expr, $RHS_TYPE:expr) => {
+ Arc::new(Arc::unwrap_or_clone(Arc::clone($LHS_TYPE)).with_data_type(
+ comparison_coercion($LHS_TYPE.data_type(), $RHS_TYPE.data_type())?,
+ ))
+ };
+}
+
/// Coercion rules for list types.
fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType>
{
use arrow::datatypes::DataType::*;
match (lhs_type, rhs_type) {
- (List(_), List(_)) => Some(lhs_type.clone()),
- (LargeList(_), List(_)) => Some(lhs_type.clone()),
- (List(_), LargeList(_)) => Some(rhs_type.clone()),
- (LargeList(_), LargeList(_)) => Some(lhs_type.clone()),
- (List(_), FixedSizeList(_, _)) => Some(lhs_type.clone()),
- (FixedSizeList(_, _), List(_)) => Some(rhs_type.clone()),
+ (List(lhs_field), List(rhs_field))
+ | (List(lhs_field), FixedSizeList(rhs_field, _))
+ | (FixedSizeList(lhs_field, _), List(rhs_field)) => {
+ Some(List(coerce_list_children!(lhs_field, rhs_field)))
+ }
+
+ (LargeList(lhs_field), List(rhs_field))
+ | (List(lhs_field), LargeList(rhs_field))
+ | (LargeList(lhs_field), LargeList(rhs_field))
+ | (LargeList(lhs_field), FixedSizeList(rhs_field, _))
+ | (FixedSizeList(lhs_field, _), LargeList(rhs_field)) => {
+ Some(LargeList(coerce_list_children!(lhs_field, rhs_field)))
+ }
+
// Coerce to the left side FixedSizeList type if the list lengths are
the same,
// otherwise coerce to list with the left type for dynamic length
- (FixedSizeList(lf, ls), FixedSizeList(_, rs)) => {
+ (FixedSizeList(lhs_field, ls), FixedSizeList(rhs_field, rs)) => {
if ls == rs {
- Some(lhs_type.clone())
+ Some(FixedSizeList(
+ coerce_list_children!(lhs_field, rhs_field),
+ *rs,
+ ))
} else {
- Some(List(Arc::clone(lf)))
+ Some(List(Arc::clone(lhs_field)))
Review Comment:
coerce_list_elements here to
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]