findepi commented on code in PR #13452:
URL: https://github.com/apache/datafusion/pull/13452#discussion_r1849980264
##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1138,27 +1134,46 @@ fn numeric_string_coercion(lhs_type: &DataType,
rhs_type: &DataType) -> Option<D
}
}
+/// Coerces two fields together, ensuring the field data (name and
nullability) is correctly set.
+fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) ->
Option<FieldRef> {
+ let data_types = vec![lhs_field.data_type().clone(),
rhs_field.data_type().clone()];
+ Some(Arc::new(
+ (**lhs_field)
+ .clone()
+ .with_data_type(type_union_resolution(&data_types)?)
+ .with_nullable(lhs_field.is_nullable() || rhs_field.is_nullable()),
+ ))
+}
+
/// 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()),
+ (
+ LargeList(lhs_field),
+ List(rhs_field) | LargeList(rhs_field) | FixedSizeList(rhs_field,
_),
Review Comment:
- Let's maybe add listview to the mix. it's hard to test, but why not be
future-proof here?
- let's maybe reorder clauses so that it's clear that any list types are
handled
```rust
match (lhs_type, rhs_type) {
// 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(lhs_field, ls), FixedSizeList(rhs_field, rs)) if ls
== rs => Some(
FixedSizeList(coerce_list_children(lhs_field, rhs_field)?, *rs),
),
// Left is a LargeList[View] or right is a LargeList[View]
(
LargeList(lhs_field) | LargeListView(lhs_field),
List(rhs_field)
| ListView(rhs_field)
| LargeList(rhs_field)
| LargeListView(rhs_field)
| FixedSizeList(rhs_field, _),
)
| (
List(lhs_field)
| ListView(lhs_field)
| FixedSizeList(lhs_field, _)
| LargeList(lhs_field)
| LargeListView(lhs_field),
LargeList(rhs_field) | LargeListView(rhs_field),
) => Some(LargeList(coerce_list_children(lhs_field, rhs_field)?)),
// Left and right are lists
(
List(lhs_field) | ListView(lhs_field) | FixedSizeList(lhs_field,
_),
List(rhs_field) | ListView(rhs_field) | FixedSizeList(rhs_field,
_),
) => Some(List(coerce_list_children(lhs_field, rhs_field)?)),
_ => None,
}
```
--
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]