Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions datafusion/functions-nested/src/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use datafusion_common::utils::{
};
use datafusion_common::{
cast::as_generic_list_array,
exec_err, plan_err,
exec_err, internal_err, plan_err,
utils::{list_ndims, take_function_args},
};
use datafusion_expr::binary::type_union_resolution;
Expand Down Expand Up @@ -439,10 +439,21 @@ fn concat_internal<O: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
}

let data_type = list_arrays[0].value_type();
// Preserve the input list's inner field (name, nullability, metadata) instead
// of creating a new default field, matching the promised return type.
let field = match list_arrays[0].data_type() {
DataType::List(field) | DataType::LargeList(field) => Arc::clone(field),
other => {
return internal_err!(
"array_concat got unexpected data type: {}",
other
);
}
};
let data = mutable.freeze();

Ok(Arc::new(GenericListArray::<O>::try_new(
Arc::new(Field::new_list_field(data_type, true)),
field,
OffsetBuffer::new(offsets.into()),
arrow::array::make_array(data),
valid,
Expand Down Expand Up @@ -564,8 +575,20 @@ where

let data = mutable.freeze();

// Preserve the input list's inner field (name, nullability, metadata) instead
// of creating a new default field, matching the promised return type.
let field = match list_array.data_type() {
DataType::List(field) | DataType::LargeList(field) => Arc::clone(field),
other => {
return internal_err!(
"array_append/array_prepend got unexpected data type: {}",
other
);
}
};

Ok(Arc::new(GenericListArray::<O>::try_new(
Arc::new(Field::new_list_field(data_type.to_owned(), true)),
field,
OffsetBuffer::new(offsets.into()),
arrow::array::make_array(data),
None,
Expand Down
30 changes: 27 additions & 3 deletions datafusion/functions-nested/src/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use arrow::buffer::OffsetBuffer;
use arrow::datatypes::{DataType, Field};
use datafusion_common::cast::as_int64_array;
use datafusion_common::utils::ListCoercion;
use datafusion_common::{Result, ScalarValue, exec_err, utils::take_function_args};
use datafusion_common::{Result, ScalarValue, exec_err, internal_err, utils::take_function_args};
use datafusion_expr::{
ArrayFunctionArgument, ArrayFunctionSignature, ColumnarValue, Documentation,
ScalarFunctionArgs, ScalarUDFImpl, Signature, TypeSignature, Volatility,
Expand Down Expand Up @@ -501,8 +501,20 @@ fn general_replace<O: OffsetSizeTrait>(

let data = mutable.freeze();

// Preserve the input list's inner field (name, nullability, metadata) instead
// of creating a new default field, matching the promised return type.
let field = match list_array.data_type() {
DataType::List(field) | DataType::LargeList(field) => Arc::clone(field),
other => {
return internal_err!(
"array_replace got unexpected data type: {}",
other
);
}
};

Ok(Arc::new(GenericListArray::<O>::try_new(
Arc::new(Field::new_list_field(list_array.value_type(), true)),
field,
OffsetBuffer::<O>::new(offsets.into()),
arrow::array::make_array(data),
valid.finish(),
Expand Down Expand Up @@ -597,8 +609,20 @@ fn general_replace_with_scalar<O: OffsetSizeTrait>(

let data = mutable.freeze();

// Preserve the input list's inner field (name, nullability, metadata) instead
// of creating a new default field, matching the promised return type.
let field = match list_array.data_type() {
DataType::List(field) | DataType::LargeList(field) => Arc::clone(field),
other => {
return internal_err!(
"array_replace got unexpected data type: {}",
other
);
}
};

Ok(Arc::new(GenericListArray::<O>::try_new(
Arc::new(Field::new_list_field(list_array.value_type(), true)),
field,
OffsetBuffer::new(offsets.into()),
arrow::array::make_array(data),
list_array.nulls().cloned(),
Expand Down