From 1e82884f3d12f55260e007b0cb42795635d3b470 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Fri, 1 Nov 2024 21:37:59 +0100 Subject: [PATCH] Use from_unary for contains with string view from_unary takes care of nulls --- arrow-string/src/predicate.rs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/arrow-string/src/predicate.rs b/arrow-string/src/predicate.rs index 2bff39786edb..15a5cee6c40e 100644 --- a/arrow-string/src/predicate.rs +++ b/arrow-string/src/predicate.rs @@ -114,27 +114,9 @@ impl<'a> Predicate<'a> { Predicate::IEqAscii(v) => BooleanArray::from_unary(array, |haystack| { haystack.eq_ignore_ascii_case(v) != negate }), - Predicate::Contains(finder) => { - if let Some(string_view_array) = array.as_any().downcast_ref::() { - let nulls = string_view_array.logical_nulls(); - BooleanArray::from( - string_view_array - .bytes_iter() - .enumerate() - .map(|(idx, haystack)| { - if nulls.as_ref().map(|n| n.is_null(idx)).unwrap_or_default() { - return None; - } - Some(finder.find(haystack).is_some() != negate) - }) - .collect::>(), - ) - } else { - BooleanArray::from_unary(array, |haystack| { - finder.find(haystack.as_bytes()).is_some() != negate - }) - } - } + Predicate::Contains(finder) => BooleanArray::from_unary(array, |haystack| { + finder.find(haystack.as_bytes()).is_some() != negate + }), Predicate::StartsWith(v) => { if let Some(string_view_array) = array.as_any().downcast_ref::() { let nulls = string_view_array.logical_nulls();