Skip to content

Commit 5500b11

Browse files
authored
Handle empty rows for array_distinct (#13810)
* handle empty array distinct * ignore * fix --------- Co-authored-by: Cyprien Huet <[email protected]>
1 parent 452a8f4 commit 5500b11

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

datafusion/functions-nested/src/set_ops.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ fn general_array_distinct<OffsetSize: OffsetSizeTrait>(
533533
array: &GenericListArray<OffsetSize>,
534534
field: &FieldRef,
535535
) -> Result<ArrayRef> {
536+
if array.len() == 0 {
537+
return Ok(Arc::new(array.clone()) as ArrayRef);
538+
}
536539
let dt = array.value_type();
537540
let mut offsets = Vec::with_capacity(array.len());
538541
offsets.push(OffsetSize::usize_as(0));

datafusion/sqllogictest/test_files/array.slt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5660,6 +5660,20 @@ select count(*) from arrays where 'X'>any(column3);
56605660
#----
56615661
#NULL
56625662

5663+
# test with empty row, the row that does not match the condition has row count 0
5664+
statement ok
5665+
create table t1(a int, b int) as values (100, 1), (101, 2), (102, 3), (101, 2);
5666+
5667+
# rowsort is to ensure the order of group by is deterministic, array_sort has no effect here, since the sum() always returns single row.
5668+
query ? rowsort
5669+
select array_distinct([sum(a)]) from t1 where a > 100 group by b;
5670+
----
5671+
[102]
5672+
[202]
5673+
5674+
statement ok
5675+
drop table t1;
5676+
56635677
query ?
56645678
select array_distinct([]);
56655679
----
@@ -7129,7 +7143,7 @@ select array_resize(arrow_cast(NULL, 'List(Int8)'), 1);
71297143
NULL
71307144

71317145
statement ok
7132-
CREATE TABLE array_resize_values
7146+
CREATE TABLE array_resize_values
71337147
AS VALUES
71347148
(make_array(1, NULL, 3, 4, 5, 6, 7, 8, 9, 10), 2, 1),
71357149
(make_array(11, 12, NULL, 14, 15, 16, 17, 18, 19, 20), 5, 2),

0 commit comments

Comments
 (0)