From 40781a3d4ecb30764c2682a141d23e1b0e879bd0 Mon Sep 17 00:00:00 2001 From: Adam Binford Date: Mon, 16 Dec 2024 12:27:13 -0500 Subject: [PATCH] Ignore null elements for scalars and arrays --- datafusion/functions-nested/src/array_has.rs | 13 ++--------- datafusion/sqllogictest/test_files/array.slt | 24 ++++++++++---------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/datafusion/functions-nested/src/array_has.rs b/datafusion/functions-nested/src/array_has.rs index 0ac1578b6d48..719b257aca96 100644 --- a/datafusion/functions-nested/src/array_has.rs +++ b/datafusion/functions-nested/src/array_has.rs @@ -214,12 +214,7 @@ fn array_has_dispatch_for_array( 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())) @@ -252,11 +247,7 @@ fn array_has_dispatch_for_scalar( 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))) diff --git a/datafusion/sqllogictest/test_files/array.slt b/datafusion/sqllogictest/test_files/array.slt index 714d1cfb0ec9..7df178bbb644 100644 --- a/datafusion/sqllogictest/test_files/array.slt +++ b/datafusion/sqllogictest/test_files/array.slt @@ -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 @@ -5362,8 +5362,8 @@ from array_has_table_null; true true false -NULL -NULL +false +false query B select array_has(column1, column2) @@ -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 @@ -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 @@ -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)),