Skip to content

Commit

Permalink
Use from_unary for contains with string view
Browse files Browse the repository at this point in the history
from_unary takes care of nulls
  • Loading branch information
findepi committed Nov 1, 2024
1 parent 65d52ff commit 1e82884
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions arrow-string/src/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<StringViewArray>() {
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::<Vec<_>>(),
)
} 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::<StringViewArray>() {
let nulls = string_view_array.logical_nulls();
Expand Down

0 comments on commit 1e82884

Please sign in to comment.