zhiqiang-hhhh commented on code in PR #27842:
URL: https://github.com/apache/doris/pull/27842#discussion_r1470523502
##########
be/src/vec/functions/like.cpp:
##########
@@ -453,24 +453,30 @@ void FunctionLike::convert_like_pattern(LikeSearchState*
state, const std::strin
bool is_escaped = false;
for (size_t i = 0; i < pattern.size(); ++i) {
- if (!is_escaped && pattern[i] == '%') {
- re_pattern->append(".*");
- } else if (!is_escaped && pattern[i] == '_') {
- re_pattern->append(".");
- // check for escape char before checking for regex special chars,
they might overlap
- } else if (!is_escaped && pattern[i] == state->escape_char) {
- is_escaped = true;
- } else if (pattern[i] == '.' || pattern[i] == '[' || pattern[i] == ']'
||
- pattern[i] == '{' || pattern[i] == '}' || pattern[i] == '('
||
- pattern[i] == ')' || pattern[i] == '\\' || pattern[i] ==
'*' ||
- pattern[i] == '+' || pattern[i] == '?' || pattern[i] == '|'
||
- pattern[i] == '^' || pattern[i] == '$') {
- // escape all regex special characters; see list at
- re_pattern->append("\\");
- re_pattern->append(1, pattern[i]);
- is_escaped = false;
+ if (!is_escaped) {
+ switch (pattern[i]) {
+ case '%':
+ re_pattern->append(".*");
+ break;
+ case '_':
+ re_pattern->append(".");
+ break;
+ default:
+ is_escaped = pattern[i] == state->escape_char;
+ if (!is_escaped) {
+ re_pattern->append(1, pattern[i]);
+ }
+ break;
+ }
} else {
- // regular character or escaped special character
+ if (pattern[i] == '.' || pattern[i] == '[' || pattern[i] == ']' ||
pattern[i] == '{' ||
Review Comment:
these characters have special meaning in re2 so they must be escaped
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]