Skip to content

Commit

Permalink
Fix skip custom escape (facebookincubator#11091)
Browse files Browse the repository at this point in the history
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: facebookincubator#11091

Reviewed By: Yuhta, amitkdutta

Differential Revision: D63395708

Pulled By: kagamiori

fbshipit-source-id: e5eb651695f27fe5ff88b72963aa70d4a550ba7a
  • Loading branch information
skadilover authored and facebook-github-bot committed Sep 26, 2024
1 parent 5a6a744 commit 50784a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions velox/functions/lib/Re2Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2202,13 +2202,16 @@ std::shared_ptr<exec::VectorFunction> 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<OptimizedLike<PatternKind::kSubstrings>>(
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<OptimizedLike<PatternKind::kSubstrings>>(
patternMetadata);
}
}

patternMetadata =
determinePatternKind(std::string_view(pattern), escapeChar);
} catch (...) {
Expand Down
1 change: 1 addition & 0 deletions velox/functions/lib/tests/Re2FunctionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ TEST_F(Re2FunctionsTest, likePatternAndEscape) {
testLike("a%c", "%#%%", '#', true);
testLike("%cd", "%#%%", '#', true);
testLike("cde", "%#%%", '#', false);
testLike("///__", "%//%/%", '/', false);

testLike(
"abcd",
Expand Down

0 comments on commit 50784a5

Please sign in to comment.