Skip to content

Commit 6ab16cc

Browse files
authored
bug: fix array_remove_* with NULLS (#21013)
## 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 #21011 . ## Rationale for this change Handle correctly `array_remove_*` functions if NULL is a value to delete <!-- 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. --> ## 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. --> ## 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)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent e74e58f commit 6ab16cc

2 files changed

Lines changed: 97 additions & 5 deletions

File tree

datafusion/functions-nested/src/remove.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ fn general_remove<OffsetSize: OffsetSizeTrait>(
390390
let mut valid = NullBufferBuilder::new(list_array.len());
391391

392392
for (row_index, offset_window) in list_array.offsets().windows(2).enumerate() {
393-
if list_array.is_null(row_index) {
393+
if list_array.is_null(row_index) || element_array.is_null(row_index) {
394394
offsets.push(offsets[row_index]);
395395
valid.append_null();
396396
continue;

datafusion/sqllogictest/test_files/array.slt

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5528,21 +5528,47 @@ select
55285528
array_remove(make_array(1, null, 2), null),
55295529
array_remove(make_array(1, null, 2, null), null);
55305530
----
5531-
[1, 2] [1, 2, NULL]
5531+
NULL NULL
55325532

55335533
query ??
55345534
select
55355535
array_remove(arrow_cast(make_array(1, null, 2), 'LargeList(Int64)'), null),
55365536
array_remove(arrow_cast(make_array(1, null, 2, null), 'LargeList(Int64)'), null);
55375537
----
5538-
[1, 2] [1, 2, NULL]
5538+
NULL NULL
55395539

55405540
query ??
55415541
select
55425542
array_remove(arrow_cast(make_array(1, null, 2), 'FixedSizeList(3, Int64)'), null),
55435543
array_remove(arrow_cast(make_array(1, null, 2, null), 'FixedSizeList(4, Int64)'), null);
55445544
----
5545-
[1, 2] [1, 2, NULL]
5545+
NULL NULL
5546+
5547+
# array_remove with null element from column
5548+
query ?
5549+
select array_remove(column1, column2) from (values
5550+
(make_array(1, 2, 3), 2),
5551+
(make_array(4, 5, 6), null),
5552+
(make_array(7, 8, 9), 8),
5553+
(null, 1)
5554+
) as t(column1, column2);
5555+
----
5556+
[1, 3]
5557+
NULL
5558+
[7, 9]
5559+
NULL
5560+
5561+
# array_remove with null element from column (LargeList)
5562+
query ?
5563+
select array_remove(column1, column2) from (values
5564+
(arrow_cast(make_array(1, 2, 3), 'LargeList(Int64)'), 2),
5565+
(arrow_cast(make_array(4, 5, 6), 'LargeList(Int64)'), null),
5566+
(arrow_cast(make_array(7, 8, 9), 'LargeList(Int64)'), 8)
5567+
) as t(column1, column2);
5568+
----
5569+
[1, 3]
5570+
NULL
5571+
[7, 9]
55465572

55475573
# array_remove scalar function #2 (element is list)
55485574
query ??
@@ -5685,6 +5711,46 @@ select array_remove(make_array([1, 2, 3], [4, 5, 6], [4, 5, 6], [10, 11, 12], [1
56855711

56865712
## array_remove_n (aliases: `list_remove_n`)
56875713

5714+
# array_remove_n with null element scalar
5715+
query ??
5716+
select array_remove_n(make_array(1, 2, 2, 1, 1), NULL, 2),
5717+
array_remove_n(make_array(1, 2, 2, 1, 1), 2, 2);
5718+
----
5719+
NULL [1, 1, 1]
5720+
5721+
# array_remove_n with null element scalar (LargeList)
5722+
query ??
5723+
select array_remove_n(arrow_cast(make_array(1, 2, 2, 1, 1), 'LargeList(Int64)'), NULL, 2),
5724+
array_remove_n(arrow_cast(make_array(1, 2, 2, 1, 1), 'LargeList(Int64)'), 2, 2);
5725+
----
5726+
NULL [1, 1, 1]
5727+
5728+
# array_remove_n with null element from column
5729+
query ?
5730+
select array_remove_n(column1, column2, column3) from (values
5731+
(make_array(1, 2, 2, 1, 1), 2, 2),
5732+
(make_array(3, 4, 4, 3, 3), null, 2),
5733+
(make_array(5, 6, 6, 5, 5), 6, 1),
5734+
(null, 1, 1)
5735+
) as t(column1, column2, column3);
5736+
----
5737+
[1, 1, 1]
5738+
NULL
5739+
[5, 6, 5, 5]
5740+
NULL
5741+
5742+
# array_remove_n with null element from column (LargeList)
5743+
query ?
5744+
select array_remove_n(column1, column2, column3) from (values
5745+
(arrow_cast(make_array(1, 2, 2, 1, 1), 'LargeList(Int64)'), 2, 2),
5746+
(arrow_cast(make_array(3, 4, 4, 3, 3), 'LargeList(Int64)'), null, 2),
5747+
(arrow_cast(make_array(5, 6, 6, 5, 5), 'LargeList(Int64)'), 6, 1)
5748+
) as t(column1, column2, column3);
5749+
----
5750+
[1, 1, 1]
5751+
NULL
5752+
[5, 6, 5, 5]
5753+
56885754
# array_remove_n scalar function #1
56895755
query ???
56905756
select array_remove_n(make_array(1, 2, 2, 1, 1), 2, 2), array_remove_n(make_array(1.0, 2.0, 2.0, 1.0, 1.0), 1.0, 2), array_remove_n(make_array('h', 'e', 'l', 'l', 'o'), 'l', 3);
@@ -5777,7 +5843,33 @@ select array_remove_n(make_array([1, 2, 3], [4, 5, 6], [4, 5, 6], [10, 11, 12],
57775843
query ?
57785844
select array_remove_all(make_array(1, 2, 2, 1, 1), NULL);
57795845
----
5780-
[1, 2, 2, 1, 1]
5846+
NULL
5847+
5848+
# array_remove_all with null element from column
5849+
query ?
5850+
select array_remove_all(column1, column2) from (values
5851+
(make_array(1, 2, 2, 1, 1), 2),
5852+
(make_array(3, 4, 4, 3, 3), null),
5853+
(make_array(5, 6, 6, 5, 5), 6),
5854+
(null, 1)
5855+
) as t(column1, column2);
5856+
----
5857+
[1, 1, 1]
5858+
NULL
5859+
[5, 5, 5]
5860+
NULL
5861+
5862+
# array_remove_all with null element from column (LargeList)
5863+
query ?
5864+
select array_remove_all(column1, column2) from (values
5865+
(arrow_cast(make_array(1, 2, 2, 1, 1), 'LargeList(Int64)'), 2),
5866+
(arrow_cast(make_array(3, 4, 4, 3, 3), 'LargeList(Int64)'), null),
5867+
(arrow_cast(make_array(5, 6, 6, 5, 5), 'LargeList(Int64)'), 6)
5868+
) as t(column1, column2);
5869+
----
5870+
[1, 1, 1]
5871+
NULL
5872+
[5, 5, 5]
57815873

57825874
# array_remove_all scalar function #1
57835875
query ???

0 commit comments

Comments
 (0)