Skip to content

Commit

Permalink
Fix error on array_distinct when input is empty #13810 (#14034)
Browse files Browse the repository at this point in the history
* fix

* add test

* oops

---------

Co-authored-by: Cyprien Huet <[email protected]>
  • Loading branch information
cht42 and Cyprien Huet authored Jan 8, 2025
1 parent b0bd899 commit 05b6f93
Show file tree
Hide file tree
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
Expand Up @@ -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();
Expand Down Expand Up @@ -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)?;
Expand Down
5 changes: 5 additions & 0 deletions datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
----
Expand Down

0 comments on commit 05b6f93

Please sign in to comment.