Skip to content

Commit

Permalink
Fix error on array_distinct when input is empty apache#13810 (apach…
Browse files Browse the repository at this point in the history
…e#14034)

* fix

* add test

* oops

---------

Co-authored-by: Cyprien Huet <[email protected]>
cht42 and cht42 authored Jan 8, 2025

Verified

This commit was signed with the committer’s verified signature.
1 parent b0bd899 commit 05b6f93
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion datafusion/functions-nested/src/set_ops.rs
Original file line number Diff line number Diff line change
@@ -513,7 +513,7 @@ fn general_array_distinct<OffsetSize: OffsetSizeTrait>(
array: &GenericListArray<OffsetSize>,
field: &FieldRef,
) -> Result<ArrayRef> {
if array.len() == 0 {
if array.is_empty() {
return Ok(Arc::new(array.clone()) as ArrayRef);
}
let dt = array.value_type();
@@ -542,6 +542,9 @@ fn general_array_distinct<OffsetSize: OffsetSizeTrait>(
};
new_arrays.push(array);
}
if new_arrays.is_empty() {
return Ok(Arc::new(array.clone()) as ArrayRef);
}
let offsets = OffsetBuffer::new(offsets.into());
let new_arrays_ref = new_arrays.iter().map(|v| v.as_ref()).collect::<Vec<_>>();
let values = compute::concat(&new_arrays_ref)?;
5 changes: 5 additions & 0 deletions datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
@@ -5681,6 +5681,11 @@ select array_distinct(a) from values ([1, 2, 3]), (null), ([1, 3, 1]) as X(a);
NULL
[1, 3]

query ?
select array_distinct(arrow_cast(null, 'LargeList(Int64)'));
----
NULL

query ?
select array_distinct([]);
----

0 comments on commit 05b6f93

Please sign in to comment.