Skip to content
Merged
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
3 changes: 2 additions & 1 deletion datafusion/functions-nested/src/array_has.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,8 @@ fn array_has_all_and_any_dispatch<'a>(
ComparisonType::All => BooleanBuffer::new_set(haystack.len()),
ComparisonType::Any => BooleanBuffer::new_unset(haystack.len()),
};
Ok(Arc::new(BooleanArray::from(buffer)))
let nulls = NullBuffer::union(haystack.nulls(), needle.nulls());
Ok(Arc::new(BooleanArray::new(buffer, nulls)))
} else {
match needle.value_type() {
DataType::Utf8 | DataType::LargeUtf8 | DataType::Utf8View => {
Expand Down
17 changes: 17 additions & 0 deletions datafusion/sqllogictest/test_files/array/array_has.slt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ query error array_has does not support type 'Null'
select array_has_all([], null),
array_has_all([1, 2, 3], null);

# Preserve NULL rows when all needles are NULL or empty
query BB
WITH t(id, haystack, needle) AS (
VALUES
(1, [1, 2], arrow_cast(NULL, 'List(Int64)')),
(2, arrow_cast(NULL, 'List(Int64)'), arrow_cast([], 'List(Int64)')),
(3, [3, 4], arrow_cast([], 'List(Int64)'))
)
SELECT array_has_any(haystack, needle),
array_has_all(haystack, needle)
FROM t
ORDER BY id;
----
NULL NULL
NULL NULL
false true

query BBBBBBBBBBBB
select array_has(make_array(1,2), 1),
array_has(make_array(1,2,NULL), 1),
Expand Down