This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 6590ea31e8 fix length error with `array_has` (#12459)
6590ea31e8 is described below

commit 6590ea31e88774ec45c14ff72f160f85be0cbabe
Author: Samuel Colvin <[email protected]>
AuthorDate: Sat Sep 14 11:12:19 2024 +0100

    fix length error with `array_has` (#12459)
    
    * fix length error with array_has
    
    * move test
    
    * add license
    
    * move test
    
    * add pure sql reproduction
    
    * bump ci
    
    * update slt, remove dedicated test
---
 datafusion/functions-nested/src/array_has.rs |  6 +++++-
 datafusion/sqllogictest/test_files/array.slt | 13 +++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/datafusion/functions-nested/src/array_has.rs 
b/datafusion/functions-nested/src/array_has.rs
index 7f66eba5df..dec964df21 100644
--- a/datafusion/functions-nested/src/array_has.rs
+++ b/datafusion/functions-nested/src/array_has.rs
@@ -21,6 +21,7 @@ use arrow::array::{Array, ArrayRef, BooleanArray, 
OffsetSizeTrait};
 use arrow::datatypes::DataType;
 use arrow::row::{RowConverter, Rows, SortField};
 use arrow_array::{Datum, GenericListArray, Scalar};
+use arrow_buffer::BooleanBuffer;
 use datafusion_common::cast::as_generic_list_array;
 use datafusion_common::utils::string_utils::string_array_to_vec;
 use datafusion_common::{exec_err, Result, ScalarValue};
@@ -200,7 +201,10 @@ fn array_has_dispatch_for_scalar<O: OffsetSizeTrait>(
     // If first argument is empty list (second argument is non-null), return 
false
     // i.e. array_has([], non-null element) -> false
     if values.len() == 0 {
-        return Ok(Arc::new(BooleanArray::from(vec![Some(false)])));
+        return Ok(Arc::new(BooleanArray::new(
+            BooleanBuffer::new_unset(haystack.len()),
+            None,
+        )));
     }
     let eq_array = compare_with_eq(values, needle, is_nested)?;
     let mut final_contained = vec![None; haystack.len()];
diff --git a/datafusion/sqllogictest/test_files/array.slt 
b/datafusion/sqllogictest/test_files/array.slt
index 72b057b444..b7d60b5058 100644
--- a/datafusion/sqllogictest/test_files/array.slt
+++ b/datafusion/sqllogictest/test_files/array.slt
@@ -7086,6 +7086,16 @@ select [1,2,3]::int[], [['1']]::int[][], 
arrow_typeof([]::text[]);
 ----
 [1, 2, 3] [[1]] List(Field { name: "item", data_type: Utf8, nullable: true, 
dict_id: 0, dict_is_ordered: false, metadata: {} })
 
+# test empty arrays return length
+# issue: https://github.com/apache/datafusion/pull/12459
+statement ok
+create table values_all_empty (a int[]) as values ([]), ([]);
+
+query B
+select array_has(a, 1) from values_all_empty;
+----
+false
+false
 
 ### Delete tables
 
@@ -7259,3 +7269,6 @@ drop table fixed_size_arrays_values_without_nulls;
 
 statement ok
 drop table test_create_array_table;
+
+statement ok
+drop table values_all_empty;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to