From 50784a5a58faadecfa3dc4e58532f89bee2dcd48 Mon Sep 17 00:00:00 2001 From: "hengjiang.ly" Date: Wed, 25 Sep 2024 17:36:04 -0700 Subject: [PATCH] Fix skip custom escape (#11091) Summary: Fix csutom escape char for substrings-search in constant like pattern. The exsit ut has covered the custom-escape case but escape char '#' is just not supported by substrings-search ``` testLike("%cd", "%#%%", '#', true); testLike("cde", "%#%%", '#', false); ``` Add ut to cover the case: ``` testLike("///__", "%//%/%", '/', false); ``` Pull Request resolved: https://github.com/facebookincubator/velox/pull/11091 Reviewed By: Yuhta, amitkdutta Differential Revision: D63395708 Pulled By: kagamiori fbshipit-source-id: e5eb651695f27fe5ff88b72963aa70d4a550ba7a --- velox/functions/lib/Re2Functions.cpp | 15 +++++++++------ velox/functions/lib/tests/Re2FunctionsTest.cpp | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/velox/functions/lib/Re2Functions.cpp b/velox/functions/lib/Re2Functions.cpp index a3bbfc248a98..44f8b66e31b9 100644 --- a/velox/functions/lib/Re2Functions.cpp +++ b/velox/functions/lib/Re2Functions.cpp @@ -2202,13 +2202,16 @@ std::shared_ptr makeLike( PatternMetadata patternMetadata = PatternMetadata::generic(); try { // Fast path for substrings search. - auto substrings = - PatternMetadata::parseSubstrings(std::string_view(pattern)); - if (substrings.size() > 0) { - patternMetadata = PatternMetadata::substrings(std::move(substrings)); - return std::make_shared>( - patternMetadata); + if (!escapeChar.has_value()) { + auto substrings = + PatternMetadata::parseSubstrings(std::string_view(pattern)); + if (substrings.size() > 0) { + patternMetadata = PatternMetadata::substrings(std::move(substrings)); + return std::make_shared>( + patternMetadata); + } } + patternMetadata = determinePatternKind(std::string_view(pattern), escapeChar); } catch (...) { diff --git a/velox/functions/lib/tests/Re2FunctionsTest.cpp b/velox/functions/lib/tests/Re2FunctionsTest.cpp index 2ff23abae75e..3197c750a067 100644 --- a/velox/functions/lib/tests/Re2FunctionsTest.cpp +++ b/velox/functions/lib/tests/Re2FunctionsTest.cpp @@ -939,6 +939,7 @@ TEST_F(Re2FunctionsTest, likePatternAndEscape) { testLike("a%c", "%#%%", '#', true); testLike("%cd", "%#%%", '#', true); testLike("cde", "%#%%", '#', false); + testLike("///__", "%//%/%", '/', false); testLike( "abcd",