Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix array_has_all and array_has_any with empty array #15039

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions datafusion/functions-nested/src/array_has.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,13 @@ fn array_has_all_and_any_dispatch<O: OffsetSizeTrait>(
) -> Result<ArrayRef> {
let haystack = as_generic_list_array::<O>(haystack)?;
let needle = as_generic_list_array::<O>(needle)?;
if needle.values().len() == 0 {
let buffer = match comparison_type {
ComparisonType::All => BooleanBuffer::new_set(haystack.len()),
ComparisonType::Any => BooleanBuffer::new_unset(haystack.len()),
};
return Ok(Arc::new(BooleanArray::from(buffer)));
}
match needle.data_type() {
DataType::Utf8 | DataType::LargeUtf8 | DataType::Utf8View => {
array_has_all_and_any_string_internal::<O>(haystack, needle, comparison_type)
Expand Down
9 changes: 9 additions & 0 deletions datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -5818,6 +5818,15 @@ false false false false
false false false false
false false false false

query BBBB
select array_has_all(make_array(1,2,3), []),
array_has_any(make_array(1,2,3), []),
array_has_all(make_array('aa','bb','cc'), []),
array_has_any(make_array('aa','bb','cc'), []),
;
----
true false true false

query BBBBBBBBBBBBB
select array_has_all(make_array(1,2,3), make_array(1,3)),
array_has_all(make_array(1,2,3), make_array(1,4)),
Expand Down