You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/12/09 11:27:12 UTC
[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3303: refactor: Merge similar functions `ilike_scalar` and `nilike_scalar`
tustvold commented on code in PR #3303:
URL: https://github.com/apache/arrow-rs/pull/3303#discussion_r1044357464
##########
arrow-string/src/like.rs:
##########
@@ -589,62 +588,39 @@ fn ilike_scalar_op<'a, F: Fn(bool) -> bool, L: ArrayAccessor<Item = &'a str>>(
right: &str,
op: F,
) -> Result<BooleanArray, ArrowError> {
- let null_bit_buffer = left.data().null_buffer().cloned();
- let bytes = bit_util::ceil(left.len(), 8);
- let mut bool_buf = MutableBuffer::from_len_zeroed(bytes);
- let bool_slice = bool_buf.as_slice_mut();
-
if !right.contains(is_like_pattern) {
// fast path, can use equals
let right_uppercase = right.to_uppercase();
- for i in 0..left.len() {
- unsafe {
- if op(left.value_unchecked(i).to_uppercase() == right_uppercase) {
- bit_util::set_bit(bool_slice, i);
- }
- }
- }
+
+ Ok(BooleanArray::from_unary(left, |item| {
+ op(item.to_uppercase() == right_uppercase)
+ }))
} else if right.ends_with('%')
&& !right.ends_with("\\%")
&& !right[..right.len() - 1].contains(is_like_pattern)
{
// fast path, can use starts_with
let start_str = &right[..right.len() - 1].to_uppercase();
- for i in 0..left.len() {
- unsafe {
- if op(left
- .value_unchecked(i)
- .to_uppercase()
- .starts_with(start_str))
- {
- bit_util::set_bit(bool_slice, i);
- }
- }
- }
+ Ok(BooleanArray::from_unary(left, |item| {
+ op(item.to_uppercase().starts_with(start_str))
+ }))
} else if right.starts_with('%') && !right[1..].contains(is_like_pattern) {
// fast path, can use ends_with
let ends_str = &right[1..].to_uppercase();
- for i in 0..left.len() {
- unsafe {
- if op(left.value_unchecked(i).to_uppercase().ends_with(ends_str)) {
- bit_util::set_bit(bool_slice, i);
- }
- }
- }
+ Ok(BooleanArray::from_unary(left, |item| {
+ op(item.to_uppercase().ends_with(ends_str))
+ }))
} else if right.starts_with('%')
&& right.ends_with('%')
+ && !right.ends_with("\\%")
Review Comment:
This appears to have been an omission from https://github.com/apache/arrow-rs/pull/2743
--
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-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org