You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by al...@apache.org on 2025/08/21 19:54:15 UTC
(datafusion) branch branch-49 updated: fix: align `array_has` null buffer for scalar (#17272) (#17274)
This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch branch-49
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/branch-49 by this push:
new 0d04475ea8 fix: align `array_has` null buffer for scalar (#17272) (#17274)
0d04475ea8 is described below
commit 0d04475ea87a56d327ab772b2b35a94c0faf5bf6
Author: Oleks V <co...@users.noreply.github.com>
AuthorDate: Thu Aug 21 12:54:09 2025 -0700
fix: align `array_has` null buffer for scalar (#17272) (#17274)
* fix: align `array_has` null buffer for scalar (#17272)
* fix: align `array_has` null buffer for scalar
* merge
---
datafusion/physical-expr-common/src/datum.rs | 21 +++++++++++++++++++--
datafusion/sqllogictest/test_files/array.slt | 15 +++++++++++++++
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/datafusion/physical-expr-common/src/datum.rs b/datafusion/physical-expr-common/src/datum.rs
index 233deff758..7084bc440e 100644
--- a/datafusion/physical-expr-common/src/datum.rs
+++ b/datafusion/physical-expr-common/src/datum.rs
@@ -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))
}
}
diff --git a/datafusion/sqllogictest/test_files/array.slt b/datafusion/sqllogictest/test_files/array.slt
index a3d9c3e1d9..14261a6e62 100644
--- a/datafusion/sqllogictest/test_files/array.slt
+++ b/datafusion/sqllogictest/test_files/array.slt
@@ -8065,6 +8065,18 @@ FixedSizeList(Field { name: "item", data_type: Int32, nullable: true, dict_id: 0
statement error
create table varying_fixed_size_col_table (a int[3]) as values ([1,2,3]), ([4,5]);
+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
@@ -8243,3 +8255,6 @@ drop table values_all_empty;
statement ok
drop table fixed_size_col_table;
+
+statement ok
+drop table array_has;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org