From 8245cef716d873fb78f8449935f53498232119db Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Fri, 14 Aug 2026 06:41:49 +0800 Subject: [PATCH 1/4] fix: preserve inner list field name, nullability and metadata in array_append/array_prepend/array_replace* --- datafusion/functions-nested/src/concat.rs | 27 +++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/datafusion/functions-nested/src/concat.rs b/datafusion/functions-nested/src/concat.rs index 5dc437b3c20b5..620efd0a2fe86 100644 --- a/datafusion/functions-nested/src/concat.rs +++ b/datafusion/functions-nested/src/concat.rs @@ -439,10 +439,21 @@ fn concat_internal(args: &[ArrayRef]) -> Result { } 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::::try_new( - Arc::new(Field::new_list_field(data_type, true)), + field, OffsetBuffer::new(offsets.into()), arrow::array::make_array(data), valid, @@ -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::::try_new( - Arc::new(Field::new_list_field(data_type.to_owned(), true)), + field, OffsetBuffer::new(offsets.into()), arrow::array::make_array(data), None, From 2a8758beffb58a8f4ce189529843cca1c4933c0b Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Fri, 14 Aug 2026 06:41:51 +0800 Subject: [PATCH 2/4] fix: preserve inner list field name, nullability and metadata in array_append/array_prepend/array_replace* --- datafusion/functions-nested/src/replace.rs | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/datafusion/functions-nested/src/replace.rs b/datafusion/functions-nested/src/replace.rs index 71d6f578158f4..ec306c9ac2adc 100644 --- a/datafusion/functions-nested/src/replace.rs +++ b/datafusion/functions-nested/src/replace.rs @@ -501,8 +501,20 @@ fn general_replace( 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::::try_new( - Arc::new(Field::new_list_field(list_array.value_type(), true)), + field, OffsetBuffer::::new(offsets.into()), arrow::array::make_array(data), valid.finish(), @@ -597,8 +609,20 @@ fn general_replace_with_scalar( 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::::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(), From 4be9e125484af844253c7111a344f22378f1e26b Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Fri, 14 Aug 2026 06:42:33 +0800 Subject: [PATCH 3/4] fix: add internal_err import --- datafusion/functions-nested/src/concat.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/functions-nested/src/concat.rs b/datafusion/functions-nested/src/concat.rs index 620efd0a2fe86..daedbe429e943 100644 --- a/datafusion/functions-nested/src/concat.rs +++ b/datafusion/functions-nested/src/concat.rs @@ -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; From 195e07529d7ba646f9be26614cf3558e72784804 Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Fri, 14 Aug 2026 06:42:35 +0800 Subject: [PATCH 4/4] fix: add internal_err import --- datafusion/functions-nested/src/replace.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/functions-nested/src/replace.rs b/datafusion/functions-nested/src/replace.rs index ec306c9ac2adc..a9ab0760ea9cc 100644 --- a/datafusion/functions-nested/src/replace.rs +++ b/datafusion/functions-nested/src/replace.rs @@ -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,