Skip to content

Commit 9dc0f4b

Browse files
authored
fix: cast [] to FixedSizeList(0, _) (apache#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 apache#123` indicates that this PR will close issue apache#123. --> - Closes apache#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. -->
1 parent 3089ace commit 9dc0f4b

5 files changed

Lines changed: 34 additions & 17 deletions

File tree

‎datafusion/common/src/scalar/mod.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11460,4 +11460,14 @@ mod tests {
1146011460
assert_eq!(utf8view_buffer_bytes(keys), one_len);
1146111461
assert_eq!(keys.value(0), strings.value(0));
1146211462
}
11463+
11464+
#[test]
11465+
fn test_zero_size_fsl() {
11466+
let s = ScalarValue::new_default(&DataType::FixedSizeList(
11467+
Field::new("a", DataType::Int32, true).into(),
11468+
0,
11469+
))
11470+
.unwrap();
11471+
assert_eq!(s.to_string(), "[]");
11472+
}
1146311473
}

‎datafusion/common/src/utils/mod.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ impl SingleRowListArrayBuilder {
613613
/// Build a single element [`FixedSizeListArray`]
614614
pub fn build_fixed_size_list_array(self, list_size: usize) -> FixedSizeListArray {
615615
let (field, arr) = self.into_field_and_arr();
616-
FixedSizeListArray::new(field, list_size as i32, arr, None)
616+
FixedSizeListArray::try_new_with_length(field, list_size as i32, arr, None, 1)
617+
.unwrap()
617618
}
618619

619620
/// Build a single element [`FixedSizeListArray`] and wrap as [`ScalarValue::FixedSizeList`]

‎datafusion/sqllogictest/test_files/array/array_empty.slt‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ select empty(arrow_cast(make_array(), 'LargeList(Int64)'));
4545
----
4646
true
4747

48-
#TODO: https://github.com/apache/datafusion/issues/9158
49-
#query B
50-
#select empty(arrow_cast(make_array(), 'FixedSizeList(0, Null)'));
51-
#----
52-
#true
48+
query B
49+
select empty(arrow_cast(make_array(), 'FixedSizeList(0, Null)'));
50+
----
51+
true
5352

5453
# empty scalar function #3
5554
query B

‎datafusion/sqllogictest/test_files/array/cardinality.slt‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,10 @@ select cardinality(arrow_cast(make_array(), 'LargeList(Int64)')), cardinality(ar
9898
----
9999
0 0
100100

101-
#TODO
102-
#https://github.com/apache/datafusion/issues/9158
103-
#query II
104-
#select cardinality(arrow_cast(make_array(), 'FixedSizeList(1, Null)')), cardinality(arrow_cast(make_array(make_array()), 'FixedSizeList(1, List(Int64))'))
105-
#----
106-
#NULL 0
101+
query II
102+
select cardinality(arrow_cast(make_array(null), 'FixedSizeList(1, Null)')), cardinality(arrow_cast(make_array(make_array()), 'FixedSizeList(1, List(Int64))'))
103+
----
104+
1 0
107105

108106
# cardinality of NULL arrays should return NULL
109107
query II

‎datafusion/sqllogictest/test_files/arrow_typeof.slt‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,21 @@ select arrow_cast(null, 'FixedSizeList(1, Int64)');
397397
----
398398
NULL
399399

400-
#TODO: arrow-rs doesn't support it yet
401-
#query ?
402-
#select arrow_cast('1', 'FixedSizeList(1, Int64)');
403-
#----
404-
#[1]
400+
query ?
401+
select arrow_cast([], 'FixedSizeList(0, Null)');
402+
----
403+
[]
404+
405+
query ? rowsort
406+
select arrow_cast(a, 'FixedSizeList(0, Null)') from values ([]), (NULL) t(a);
407+
----
408+
NULL
409+
[]
405410

411+
query ?
412+
select arrow_cast('1', 'FixedSizeList(1, Int64)');
413+
----
414+
[1]
406415

407416
query ?
408417
select arrow_cast([1], 'FixedSizeList(1, Int64)');

0 commit comments

Comments
 (0)