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
21 changes: 19 additions & 2 deletions datafusion/physical-expr-common/src/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,26 @@ pub fn compare_op_for_nested(
if matches!(op, Operator::IsDistinctFrom | Operator::IsNotDistinctFrom) {
Ok(BooleanArray::new(values, None))
} else {
// If one of the side is NULL, we returns NULL
// If one of the side is NULL, we return NULL
// i.e. NULL eq NULL -> NULL
let nulls = NullBuffer::union(l.nulls(), r.nulls());
// For nested comparisons, we need to ensure the null buffer matches the result length
let nulls = match (is_l_scalar, is_r_scalar) {
(false, false) | (true, true) => NullBuffer::union(l.nulls(), r.nulls()),
(true, false) => {
// When left is null-scalar and right is array, expand left nulls to match result length
match l.nulls().filter(|nulls| !nulls.is_valid(0)) {
Some(_) => Some(NullBuffer::new_null(len)), // Left scalar is null
None => r.nulls().cloned(), // Left scalar is non-null
}
}
(false, true) => {
// When right is null-scalar and left is array, expand right nulls to match result length
match r.nulls().filter(|nulls| !nulls.is_valid(0)) {
Some(_) => Some(NullBuffer::new_null(len)), // Right scalar is null
None => l.nulls().cloned(), // Right scalar is non-null
}
}
};
Ok(BooleanArray::new(values, nulls))
}
}
15 changes: 15 additions & 0 deletions datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -8072,6 +8072,18 @@ select [named_struct('a', 1, 'b', null)][-2];
----
NULL

statement ok
COPY (select [[true, false], [false, true]] a, [false, true] b union select [[null, null]], null) to 'test_files/scratch/array/array_has/single_file.parquet' stored as parquet;

statement ok
CREATE EXTERNAL TABLE array_has STORED AS PARQUET location 'test_files/scratch/array/array_has/single_file.parquet';

query B
select array_contains(a, b) from array_has order by 1 nulls last;
----
true
NULL

### Delete tables

statement ok
Expand Down Expand Up @@ -8250,3 +8262,6 @@ drop table values_all_empty;

statement ok
drop table fixed_size_col_table;

statement ok
drop table array_has;