gruuya commented on code in PR #9312:
URL: https://github.com/apache/arrow-datafusion/pull/9312#discussion_r1501368655
##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -372,13 +374,20 @@ fn coerced_from<'a>(
List(_) if matches!(type_from, FixedSizeList(_, _)) =>
Some(type_into.clone()),
// Only accept list and largelist with the same number of dimensions
unless the type is Null.
- // List or LargeList with different dimensions should be handled in
TypeSignature or other places before this.
+ // List or LargeList with different dimensions should be handled in
TypeSignature or other places before this
List(_) | LargeList(_)
if datafusion_common::utils::base_type(type_from).eq(&Null)
|| list_ndims(type_from) == list_ndims(type_into) =>
{
Some(type_into.clone())
}
+ // should be able to coerce wildcard fixed size list to non wildcard
fixed size list
+ FixedSizeList(_, _)
+ if matches!(type_from, FixedSizeList(_, FIXED_SIZE_LIST_WILDCARD))
+ && list_ndims(type_from) == list_ndims(type_into) =>
Review Comment:
Ok got a bit nerd-sniped here it seems, but I think the following actually
handles the nested `FixedSizeLists` too:
```rust
FixedSizeList(f_into, FIXED_SIZE_LIST_WILDCARD) => match type_from {
FixedSizeList(f_from, size_from) => {
match coerced_from(f_into.data_type(), f_from.data_type()) {
Some(data_type) if &data_type != f_into.data_type() => {
let new_field =
Arc::new(f_into.as_ref().clone().with_data_type(data_type));
Some(FixedSizeList(new_field, *size_from))
}
Some(_) => Some(FixedSizeList(f_into.clone(), *size_from)),
_ => None,
}
}
_ => None,
},
```
The following test passes (as does the one by @jayzhan211 ):
```rust
#[test]
fn test_nested_wildcard_fixed_size_lists() -> Result<()> {
let type_into = DataType::FixedSizeList(
Arc::new(Field::new(
"item",
DataType::FixedSizeList(
Arc::new(Field::new("item", DataType::Int32, false)),
FIXED_SIZE_LIST_WILDCARD,
),
false,
)),
FIXED_SIZE_LIST_WILDCARD,
);
let type_from = DataType::FixedSizeList(
Arc::new(Field::new(
"item",
DataType::FixedSizeList(
Arc::new(Field::new("item", DataType::Int8, false)),
4,
),
false,
)),
3,
);
assert_eq!(
coerced_from(&type_into, &type_from),
Some(DataType::FixedSizeList(
Arc::new(Field::new(
"item",
DataType::FixedSizeList(
Arc::new(Field::new("item", DataType::Int32, false)),
4,
),
false,
)),
3,
))
);
Ok(())
}
```
--
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]