This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-23381-301e684b583fb2d3661f73c6489f81891f1150aa in repository https://gitbox.apache.org/repos/asf/datafusion.git
commit 7d2911b651384e4a6c04a697ee8f4a8af66e13a0 Author: Jeffrey Vo <[email protected]> AuthorDate: Thu Jul 9 04:16:15 2026 +0900 fix: cast `[]` to `FixedSizeList(0, _)` (#23381) ## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #9158 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> See issue ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Add test coverage, also fix issue with constructing scalars of FixedSizeLists with 0 size since we need to explicitly specify the length. ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Yes ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> No <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --- datafusion/common/src/scalar/mod.rs | 10 ++++++++++ datafusion/common/src/utils/mod.rs | 3 ++- .../sqllogictest/test_files/array/array_empty.slt | 9 ++++----- .../sqllogictest/test_files/array/cardinality.slt | 10 ++++------ datafusion/sqllogictest/test_files/arrow_typeof.slt | 19 ++++++++++++++----- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/datafusion/common/src/scalar/mod.rs b/datafusion/common/src/scalar/mod.rs index 3d2e8d08ac..ddfe32edd4 100644 --- a/datafusion/common/src/scalar/mod.rs +++ b/datafusion/common/src/scalar/mod.rs @@ -11460,4 +11460,14 @@ mod tests { assert_eq!(utf8view_buffer_bytes(keys), one_len); assert_eq!(keys.value(0), strings.value(0)); } + + #[test] + fn test_zero_size_fsl() { + let s = ScalarValue::new_default(&DataType::FixedSizeList( + Field::new("a", DataType::Int32, true).into(), + 0, + )) + .unwrap(); + assert_eq!(s.to_string(), "[]"); + } } diff --git a/datafusion/common/src/utils/mod.rs b/datafusion/common/src/utils/mod.rs index 30a6c45dfc..f71cf23d53 100644 --- a/datafusion/common/src/utils/mod.rs +++ b/datafusion/common/src/utils/mod.rs @@ -613,7 +613,8 @@ impl SingleRowListArrayBuilder { /// Build a single element [`FixedSizeListArray`] pub fn build_fixed_size_list_array(self, list_size: usize) -> FixedSizeListArray { let (field, arr) = self.into_field_and_arr(); - FixedSizeListArray::new(field, list_size as i32, arr, None) + FixedSizeListArray::try_new_with_length(field, list_size as i32, arr, None, 1) + .unwrap() } /// Build a single element [`FixedSizeListArray`] and wrap as [`ScalarValue::FixedSizeList`] diff --git a/datafusion/sqllogictest/test_files/array/array_empty.slt b/datafusion/sqllogictest/test_files/array/array_empty.slt index 62ac5f66b7..15cf2b4860 100644 --- a/datafusion/sqllogictest/test_files/array/array_empty.slt +++ b/datafusion/sqllogictest/test_files/array/array_empty.slt @@ -45,11 +45,10 @@ select empty(arrow_cast(make_array(), 'LargeList(Int64)')); ---- true -#TODO: https://github.com/apache/datafusion/issues/9158 -#query B -#select empty(arrow_cast(make_array(), 'FixedSizeList(0, Null)')); -#---- -#true +query B +select empty(arrow_cast(make_array(), 'FixedSizeList(0, Null)')); +---- +true # empty scalar function #3 query B diff --git a/datafusion/sqllogictest/test_files/array/cardinality.slt b/datafusion/sqllogictest/test_files/array/cardinality.slt index c0ad54e97a..21e94b53b2 100644 --- a/datafusion/sqllogictest/test_files/array/cardinality.slt +++ b/datafusion/sqllogictest/test_files/array/cardinality.slt @@ -98,12 +98,10 @@ select cardinality(arrow_cast(make_array(), 'LargeList(Int64)')), cardinality(ar ---- 0 0 -#TODO -#https://github.com/apache/datafusion/issues/9158 -#query II -#select cardinality(arrow_cast(make_array(), 'FixedSizeList(1, Null)')), cardinality(arrow_cast(make_array(make_array()), 'FixedSizeList(1, List(Int64))')) -#---- -#NULL 0 +query II +select cardinality(arrow_cast(make_array(null), 'FixedSizeList(1, Null)')), cardinality(arrow_cast(make_array(make_array()), 'FixedSizeList(1, List(Int64))')) +---- +1 0 # cardinality of NULL arrays should return NULL query II diff --git a/datafusion/sqllogictest/test_files/arrow_typeof.slt b/datafusion/sqllogictest/test_files/arrow_typeof.slt index e00909ad5f..17fcb7fa36 100644 --- a/datafusion/sqllogictest/test_files/arrow_typeof.slt +++ b/datafusion/sqllogictest/test_files/arrow_typeof.slt @@ -397,12 +397,21 @@ select arrow_cast(null, 'FixedSizeList(1, Int64)'); ---- NULL -#TODO: arrow-rs doesn't support it yet -#query ? -#select arrow_cast('1', 'FixedSizeList(1, Int64)'); -#---- -#[1] +query ? +select arrow_cast([], 'FixedSizeList(0, Null)'); +---- +[] + +query ? rowsort +select arrow_cast(a, 'FixedSizeList(0, Null)') from values ([]), (NULL) t(a); +---- +NULL +[] +query ? +select arrow_cast('1', 'FixedSizeList(1, Int64)'); +---- +[1] query ? select arrow_cast([1], 'FixedSizeList(1, Int64)'); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
