Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ilike_utf8_scalar kernals #2545

Merged
merged 3 commits into from
Aug 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 19 additions & 31 deletions arrow/src/compute/kernels/comparison.rs
Original file line number Diff line number Diff line change
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