This is an automated email from the ASF dual-hosted git repository.
github-bot 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 94b68cb3c2 fix: correct edge case where null haystack returns false
instead of null (#17818)
94b68cb3c2 is described below
commit 94b68cb3c2615a767b52cb598c568a87ef50e6d8
Author: Jeffrey Vo <[email protected]>
AuthorDate: Thu Oct 2 02:45:33 2025 +1000
fix: correct edge case where null haystack returns false instead of null
(#17818)
* fix: correct edge case where haystack with null element returns false
instead of null
* clippy
---
datafusion/functions-nested/src/array_has.rs | 59 +++++++++++++++++++++++++---
1 file changed, 54 insertions(+), 5 deletions(-)
diff --git a/datafusion/functions-nested/src/array_has.rs
b/datafusion/functions-nested/src/array_has.rs
index f77cc5dd7b..43aa5f4ae6 100644
--- a/datafusion/functions-nested/src/array_has.rs
+++ b/datafusion/functions-nested/src/array_has.rs
@@ -333,7 +333,7 @@ fn array_has_dispatch_for_scalar(
let is_nested = values.data_type().is_nested();
// If first argument is empty list (second argument is non-null), return
false
// i.e. array_has([], non-null element) -> false
- if values.is_empty() {
+ if haystack.len() == 0 {
return Ok(Arc::new(BooleanArray::new(
BooleanBuffer::new_unset(haystack.len()),
None,
@@ -658,11 +658,20 @@ fn general_array_has_all_and_any_kernel(
#[cfg(test)]
mod tests {
- use arrow::array::create_array;
- use datafusion_common::utils::SingleRowListArrayBuilder;
+ use std::sync::Arc;
+
+ use arrow::{
+ array::{create_array, Array, ArrayRef, AsArray, Int32Array, ListArray},
+ buffer::OffsetBuffer,
+ datatypes::{DataType, Field},
+ };
+ use datafusion_common::{
+ config::ConfigOptions, utils::SingleRowListArrayBuilder,
DataFusionError,
+ ScalarValue,
+ };
use datafusion_expr::{
- col, execution_props::ExecutionProps, lit,
simplify::ExprSimplifyResult, Expr,
- ScalarUDFImpl,
+ col, execution_props::ExecutionProps, lit,
simplify::ExprSimplifyResult,
+ ColumnarValue, Expr, ScalarFunctionArgs, ScalarUDFImpl,
};
use crate::expr_fn::make_array;
@@ -737,4 +746,44 @@ mod tests {
assert_eq!(args, vec![col("c1"), col("c2")],);
}
+
+ #[test]
+ fn test_array_has_list_empty_child() -> Result<(), DataFusionError> {
+ let haystack_field = Arc::new(Field::new_list(
+ "haystack",
+ Field::new_list("", Field::new("", DataType::Int32, true), true),
+ true,
+ ));
+ let needle_field = Arc::new(Field::new("needle", DataType::Int32,
true));
+ let return_field = Arc::new(Field::new_list(
+ "return",
+ Field::new("", DataType::Boolean, true),
+ true,
+ ));
+
+ let haystack = ListArray::new(
+ Field::new_list_field(DataType::Int32, true).into(),
+ OffsetBuffer::new(vec![0, 0].into()),
+ Arc::new(Int32Array::from(Vec::<i32>::new())) as ArrayRef,
+ Some(vec![false].into()),
+ );
+
+ let haystack = ColumnarValue::Array(Arc::new(haystack));
+ let needle = ColumnarValue::Scalar(ScalarValue::Int32(Some(1)));
+
+ let result = ArrayHas::new().invoke_with_args(ScalarFunctionArgs {
+ args: vec![haystack, needle],
+ arg_fields: vec![haystack_field, needle_field],
+ number_rows: 1,
+ return_field,
+ config_options: Arc::new(ConfigOptions::default()),
+ })?;
+
+ let output = result.into_array(1)?;
+ let output = output.as_boolean();
+ assert_eq!(output.len(), 1);
+ assert!(output.is_null(0));
+
+ Ok(())
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]