jayzhan211 commented on code in PR #12097:
URL: https://github.com/apache/datafusion/pull/12097#discussion_r1725078425


##########
datafusion/functions-nested/src/array_has.rs:
##########
@@ -323,3 +316,97 @@ fn general_array_has_dispatch<O: OffsetSizeTrait>(
     }
     Ok(Arc::new(boolean_builder.finish()))
 }
+
+/// Public function for internal benchmark, avoid to use it in production
+pub fn array_has_dispatch<O: OffsetSizeTrait>(
+    haystack: &ArrayRef,
+    needle: &ArrayRef,
+) -> Result<ArrayRef> {
+    let haystack = as_generic_list_array::<O>(haystack)?;
+    match needle.data_type() {
+        DataType::Utf8 => array_has_string_internal::<O, i32>(haystack, 
needle),
+        DataType::LargeUtf8 => array_has_string_internal::<O, i64>(haystack, 
needle),
+        DataType::Utf8View => array_has_string_view_internal::<O>(haystack, 
needle),
+        _ => general_array_has::<O>(haystack, needle),
+    }
+}
+
+fn array_has_string_internal<O: OffsetSizeTrait, S: OffsetSizeTrait>(
+    array: &GenericListArray<O>,
+    needle: &ArrayRef,
+) -> Result<ArrayRef> {
+    let mut boolean_builder = BooleanArray::builder(array.len());
+    let needle_array = needle.as_string::<S>();
+    for (arr, element) in array.iter().zip(needle_array.iter()) {
+        match (arr, element) {
+            (Some(arr), Some(element)) => {
+                let string_arr = arr.as_string::<S>();
+                let mut res = false;
+                for sub_arr in string_arr.iter().flatten() {
+                    if sub_arr == element {
+                        res = true;
+                        break;
+                    }
+                }
+                boolean_builder.append_value(res);
+            }
+            (_, _) => {
+                boolean_builder.append_null();
+            }
+        }
+    }
+
+    Ok(Arc::new(boolean_builder.finish()))
+}
+
+fn array_has_string_view_internal<O: OffsetSizeTrait>(

Review Comment:
   I prefer not to macro these two functions



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to