sdf-jkl commented on code in PR #18363:
URL: https://github.com/apache/datafusion/pull/18363#discussion_r2475488549
##########
datafusion/functions-nested/src/flatten.rs:
##########
@@ -154,7 +158,32 @@ pub fn flatten_inner(args: &[ArrayRef]) ->
Result<ArrayRef> {
Ok(Arc::new(flattened_array) as ArrayRef)
}
LargeList(_) => {
- exec_err!("flatten does not support type '{:?}'",
array.data_type())?
+ let (inner_field, inner_offsets, inner_values, _) =
+ as_large_list_array(&values)?.clone().into_parts();
+ // Try to downcast the inner offsets to i32
+ match downcast_i64_inner_to_i32(&inner_offsets, &offsets) {
+ Ok(i32offsets) => {
+ let flattened_array = GenericListArray::<i32>::new(
+ inner_field,
+ i32offsets,
+ inner_values,
+ nulls,
+ );
+ Ok(Arc::new(flattened_array) as ArrayRef)
+ }
+ // If downcast fails we keep the offsets as is
+ Err(_) => {
+ // Fallback: keep i64 offsets → LargeList<i64>
+ let i64offsets = keep_offsets_i64(inner_offsets,
offsets);
+ let flattened_array = GenericListArray::<i64>::new(
+ inner_field,
+ i64offsets,
+ inner_values,
+ nulls,
+ );
+ Ok(Arc::new(flattened_array) as ArrayRef)
Review Comment:
I was looking at @Jefffrey's original comment suggesting that we should try
to downcast it `i32` returning a `ListArray` and alternatively return a
`LargeListArray` if downcast is not possible.
He also mentioned that upcasting the parent offsets to `LargeListArray`
blindly would be inefficient and undesirable.
I wanted to see if it's possible to infer the possibility of downcasting the
inner array offsets within the `return_type` function. Then return the matching
output type.
We could do it by checking if: `inner_offsets.last() <= i32::MAX`
--
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]