Skip to content

Commit

Permalink
Fix ilike_utf8_scalar kernals (#2545)
Browse files Browse the repository at this point in the history
* fix ilike kernals

* minor refactor for perf improvements

* Remove wrongly added file
  • Loading branch information
psvri committed Aug 23, 2022
1 parent 89f2e45 commit b2f0c65
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions arrow/src/compute/kernels/comparison.rs
Expand Up @@ -467,29 +467,24 @@ pub fn ilike_utf8_scalar<OffsetSize: OffsetSizeTrait>(

if !right.contains(is_like_pattern) {
// fast path, can use equals
let right_uppercase = right.to_uppercase();
for i in 0..left.len() {
result.append(left.value(i) == right);
result.append(left.value(i).to_uppercase() == right_uppercase);
}
} else if right.ends_with('%')
&& !right.ends_with("\\%")
&& !right[..right.len() - 1].contains(is_like_pattern)
{
// fast path, can use ends_with
// fast path, can use starts_with
let start_str = &right[..right.len() - 1].to_uppercase();
for i in 0..left.len() {
result.append(
left.value(i)
.to_uppercase()
.starts_with(&right[..right.len() - 1].to_uppercase()),
);
result.append(left.value(i).to_uppercase().starts_with(start_str));
}
} else if right.starts_with('%') && !right[1..].contains(is_like_pattern) {
// fast path, can use starts_with
// fast path, can use ends_with
let ends_str = &right[1..].to_uppercase();
for i in 0..left.len() {
result.append(
left.value(i)
.to_uppercase()
.ends_with(&right[1..].to_uppercase()),
);
result.append(left.value(i).to_uppercase().ends_with(ends_str));
}
} else {
let re_pattern = replace_like_wildcards(right)?;
Expand Down Expand Up @@ -550,31 +545,24 @@ pub fn nilike_utf8_scalar<OffsetSize: OffsetSizeTrait>(

if !right.contains(is_like_pattern) {
// fast path, can use equals
let right_uppercase = right.to_uppercase();
for i in 0..left.len() {
result.append(left.value(i) != right);
result.append(left.value(i).to_uppercase() != right_uppercase);
}
} else if right.ends_with('%')
&& !right.ends_with("\\%")
&& !right[..right.len() - 1].contains(is_like_pattern)
{
// fast path, can use ends_with
// fast path, can use starts_with
let start_str = &right[..right.len() - 1].to_uppercase();
for i in 0..left.len() {
result.append(
!left
.value(i)
.to_uppercase()
.starts_with(&right[..right.len() - 1].to_uppercase()),
);
result.append(!left.value(i).to_uppercase().starts_with(start_str));
}
} else if right.starts_with('%') && !right[1..].contains(is_like_pattern) {
// fast path, can use starts_with
// fast path, can use ends_with
let end_str = &right[1..].to_uppercase();
for i in 0..left.len() {
result.append(
!left
.value(i)
.to_uppercase()
.ends_with(&right[1..].to_uppercase()),
);
result.append(!left.value(i).to_uppercase().ends_with(end_str));
}
} else {
let re_pattern = replace_like_wildcards(right)?;
Expand Down Expand Up @@ -4181,7 +4169,7 @@ mod tests {
test_utf8_scalar!(
test_utf8_array_ilike_scalar_equals,
vec!["arrow", "parrow", "arrows", "arr"],
"arrow",
"Arrow",
ilike_utf8_scalar,
vec![true, false, false, false]
);
Expand Down Expand Up @@ -4234,8 +4222,8 @@ mod tests {

test_utf8_scalar!(
test_utf8_array_nilike_scalar_equals,
vec!["arrow", "parrow", "arrows", "arr"],
"arrow",
vec!["arRow", "parrow", "arrows", "arr"],
"Arrow",
nilike_utf8_scalar,
vec![false, true, true, true]
);
Expand Down

0 comments on commit b2f0c65

Please sign in to comment.