Skip to content

Commit

Permalink
Ignore null elements for scalars and arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimahriman committed Dec 16, 2024
1 parent 828ccff commit 40781a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
13 changes: 2 additions & 11 deletions datafusion/functions-nested/src/array_has.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,7 @@ fn array_has_dispatch_for_array<O: OffsetSizeTrait>(
let is_nested = arr.data_type().is_nested();
let needle_row = Scalar::new(needle.slice(i, 1));
let eq_array = compare_with_eq(&arr, &needle_row, is_nested)?;
let is_contained = eq_array.true_count() > 0;
if is_contained || eq_array.null_count() == 0 {
boolean_builder.append_value(is_contained);
} else {
boolean_builder.append_null();
}
boolean_builder.append_value(eq_array.true_count() > 0);
}

Ok(Arc::new(boolean_builder.finish()))
Expand Down Expand Up @@ -252,11 +247,7 @@ fn array_has_dispatch_for_scalar<O: OffsetSizeTrait>(
continue;
}
let sliced_array = eq_array.slice(start, length);
// For nested list, check number of nulls
let is_contained = sliced_array.true_count() > 0;
if is_contained || sliced_array.null_count() == 0 {
final_contained[i] = Some(is_contained);
}
final_contained[i] = Some(sliced_array.true_count() > 0);
}

Ok(Arc::new(BooleanArray::from(final_contained)))
Expand Down
24 changes: 12 additions & 12 deletions datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -5275,7 +5275,7 @@ query BB
select array_has([1, null, 2], 3),
array_has([null, null, null], 3);
----
NULL NULL
false false

#TODO: array_has_all and array_has_any cannot handle NULL
#query BBBB
Expand Down Expand Up @@ -5362,8 +5362,8 @@ from array_has_table_null;
true
true
false
NULL
NULL
false
false

query B
select array_has(column1, column2)
Expand Down Expand Up @@ -5568,9 +5568,9 @@ select array_has(column1, make_array(5, 6)),
from arrays;
----
false false false true
true false true NULL
true false true false
true false false true
false true NULL false
false true false false
NULL NULL false false
false false NULL false
false false false NULL
Expand All @@ -5583,9 +5583,9 @@ select array_has(arrow_cast(column1, 'LargeList(List(Int64))'), make_array(5, 6)
from arrays;
----
false false false true
true false true NULL
true false true false
true false false true
false true NULL false
false true false false
NULL NULL false false
false false NULL false
false false false NULL
Expand All @@ -5598,12 +5598,12 @@ select array_has(column1, make_array(5, 6)),
from fixed_size_arrays;
----
false false false true
true false true NULL
true false true false
true false false true
false true NULL false
NULL NULL false false
false false NULL false
false false false NULL
false true false false
false false false false
false false false false
false false false false

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

0 comments on commit 40781a3

Please sign in to comment.