diff --git a/arrow/src/compute/kernels/comparison.rs b/arrow/src/compute/kernels/comparison.rs index 125be912cafb..1ebd8718a595 100644 --- a/arrow/src/compute/kernels/comparison.rs +++ b/arrow/src/compute/kernels/comparison.rs @@ -360,7 +360,11 @@ pub fn like_utf8_scalar( } } } else { - let re_pattern = right.replace("%", ".*").replace("_", "."); + let re_pattern = right + .replace("%", ".*") + .replace("_", ".") + .replace("(", r#"\("#) + .replace(")", r#"\)"#); let re = Regex::new(&format!("^{}$", re_pattern)).map_err(|e| { ArrowError::ComputeError(format!( "Unable to build regex from LIKE pattern: {}", @@ -436,7 +440,11 @@ pub fn nlike_utf8_scalar( result.append(!left.value(i).ends_with(&right[1..])); } } else { - let re_pattern = right.replace("%", ".*").replace("_", "."); + let re_pattern = right + .replace("%", ".*") + .replace("_", ".") + .replace("(", r#"\("#) + .replace(")", r#"\)"#); let re = Regex::new(&format!("^{}$", re_pattern)).map_err(|e| { ArrowError::ComputeError(format!( "Unable to build regex from LIKE pattern: {}", @@ -517,7 +525,11 @@ pub fn ilike_utf8_scalar( ); } } else { - let re_pattern = right.replace("%", ".*").replace("_", "."); + let re_pattern = right + .replace("%", ".*") + .replace("_", ".") + .replace("(", r#"\("#) + .replace(")", r#"\)"#); let re = Regex::new(&format!("(?i)^{}$", re_pattern)).map_err(|e| { ArrowError::ComputeError(format!( "Unable to build regex from ILIKE pattern: {}", @@ -2228,6 +2240,13 @@ mod tests { vec![true, true, true, false, false, true, false] ); + test_utf8_scalar!( + test_utf8_array_like_scalar_escape_testing, + vec!["varchar(255)", "int(255)", "varchar", "int"], + "%(%)%", + like_utf8_scalar, + vec![true, true, false, false] + ); test_utf8_scalar!( test_utf8_array_like_scalar, vec!["arrow", "parquet", "datafusion", "flight"], @@ -2289,6 +2308,13 @@ mod tests { nlike_utf8, vec![false, false, false, true, true, false, true] ); + test_utf8_scalar!( + test_utf8_array_nlike_escape_testing, + vec!["varchar(255)", "int(255)", "varchar", "int"], + "%(%)%", + nlike_utf8_scalar, + vec![false, false, true, true] + ); test_utf8_scalar!( test_utf8_array_nlike_scalar, vec!["arrow", "parquet", "datafusion", "flight"], @@ -2336,6 +2362,13 @@ mod tests { ilike_utf8, vec![true, true, true, false, false, true, false] ); + test_utf8_scalar!( + ilike_utf8_scalar_escape_testing, + vec!["varchar(255)", "int(255)", "varchar", "int"], + "%(%)%", + ilike_utf8_scalar, + vec![true, true, false, false] + ); test_utf8_scalar!( test_utf8_array_ilike_scalar, vec!["arrow", "parquet", "datafusion", "flight"],