This is an automated email from the ASF dual-hosted git repository. joemcdonnell pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/impala.git
commit 3be15fd3598071eaeddd9b4d29e0883b95fdd14a Author: Balazs Hevele <[email protected]> AuthorDate: Mon Feb 9 12:48:03 2026 +0100 IMPALA-14731: Fix LIKE starting with % ending with escaped % The escape before the % at the end was not parsed properly as an escape wildcard. As an example, "%abc\%" matched for anything containing "abc\" (containing the backslash character), instead of any any string with the suffix "abc%". The fix is basically the same as the one for IMPALA-10849 but for the case when the pattern starts with %. New test cases were added to exprs.test. Change-Id: I6eebfaeffdb59d5d2c1cfbd331fa98d0391325e7 Reviewed-on: http://gerrit.cloudera.org:8080/23953 Reviewed-by: Csaba Ringhofer <[email protected]> Tested-by: Impala Public Jenkins <[email protected]> --- be/src/exprs/like-predicate.cc | 4 ++- .../functional-query/queries/QueryTest/exprs.test | 38 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/be/src/exprs/like-predicate.cc b/be/src/exprs/like-predicate.cc index 993f656c4..fbf5f89a9 100644 --- a/be/src/exprs/like-predicate.cc +++ b/be/src/exprs/like-predicate.cc @@ -78,7 +78,9 @@ void LikePredicate::LikePrepareInternal(FunctionContext* context, re2::RE2 ends_with_escaped_wildcard(".*\\\\%$"); string pattern_str(pattern.Ptr(), pattern.Len()); string search_string; - if (case_sensitive && RE2::FullMatch(pattern_str, substring_re, &search_string)) { + if (case_sensitive && + RE2::FullMatch(pattern_str, substring_re, &search_string) && + !RE2::FullMatch(pattern_str, ends_with_escaped_wildcard)) { state->SetSearchString(search_string); state->function_ = ConstantSubstringFn; } else if (case_sensitive && diff --git a/testdata/workloads/functional-query/queries/QueryTest/exprs.test b/testdata/workloads/functional-query/queries/QueryTest/exprs.test index b79067ede..4f0e2e8cd 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/exprs.test +++ b/testdata/workloads/functional-query/queries/QueryTest/exprs.test @@ -3272,6 +3272,44 @@ true ---- TYPES BOOLEAN ==== +---- QUERY: IMPALA-14731 +# Check that an escaped % is not treated as a wildcard character in a like +# predicate. Note this test cannot be part of the LikeTbl tests as the +# like predicate optimizations are only applied when the like predicate is a +# string literal. +select 'escape%' like '%escape\%' +---- RESULTS +true +---- TYPES +BOOLEAN +==== +---- QUERY: IMPALA-14731 +# Check that an escaped % is not treated as a wildcard character in a like +# predicate. Note this test cannot be part of the LikeTbl tests as the +# like predicate optimizations are only applied when the like predicate is a +# string literal. +select 'esc\\ape' like '%esc\%' +---- RESULTS +false +---- TYPES +BOOLEAN +==== +---- QUERY: IMPALA-10849 +# Check that unescaped % is evaluated correctly. +select 'escape' like '%esc%' +---- RESULTS +true +---- TYPES +BOOLEAN +==== +---- QUERY: IMPALA-10849 +# Check that unescaped _ is evaluated correctly. +select 'escape' like '%escap_' +---- RESULTS +true +---- TYPES +BOOLEAN +==== ---- QUERY: IMPALA-955 # Returns number of bytes in a byte string. select bytes(string_col), bytes(date_string_col) from functional.alltypestiny;
