-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(sql): fix backslash escape mechanism in LIKE
and ILIKE
operator
#3006
Conversation
core/src/test/java/io/questdb/griffin/engine/functions/regex/LikeFunctionFactoryTest.java
Show resolved
Hide resolved
core/src/test/java/io/questdb/griffin/engine/functions/regex/LikeFunctionFactoryTest.java
Show resolved
Hide resolved
core/src/test/java/io/questdb/griffin/engine/functions/regex/LikeFunctionFactoryTest.java
Outdated
Show resolved
Hide resolved
.../src/main/java/io/questdb/griffin/engine/functions/regex/AbstractLikeStrFunctionFactory.java
Outdated
Show resolved
Hide resolved
Please merge from master and fix conflict . |
# Conflicts: # core/src/test/java/io/questdb/griffin/engine/functions/regex/LikeFunctionFactoryTest.java
Thank you very much for your suggestions! Additionally, I am afraid I do not fully understand your requirement so I wrote and tested three versions that all pass the tests just in case you want me to change to another one.
for (int i = 0; i < len; i++) {
char c = pattern.charAt(i);
if (c == '\\') {
if (i + 1 < len){
i += 1;
c = pattern.charAt(i);
if (c == '_' || c == '%') {
sink.put(c);
} else if(c == '\\'){
sink.put("\\\\");
} else if ("[](){}.*+?$^|#".indexOf(c) != -1) {
sink.put("\\\\\\");
sink.put(c);
} else {
sink.put("\\\\");
sink.put(c);
}
} else {
sink.put("\\\\"); // the backslash is the last character
}
} else if (c == '_')
sink.put('.');
else if (c == '%')
sink.put(".*?");
else if ("[](){}.*+?$^|#".indexOf(c) != -1) {
sink.put("\\");
sink.put(c);
} else
sink.put(c);
}
for (int i = 0; i < len; i++) {
char c = pattern.charAt(i);
if (c == '_')
sink.put('.');
else if (c == '%')
sink.put(".*?");
else if( c == '\\' && i+1 < len && "_%".indexOf(pattern.charAt(i+1)) != -1){
i += 1;
sink.put(pattern.charAt(i));
}
else if (c == '\\' && i+1 < len && pattern.charAt(i+1) == '\\'){
i += 1;
sink.put("\\\\");
}
else if ("[](){}.*+?$^|#\\".indexOf(c) != -1) {
sink.put("\\");
sink.put(c);
} else
sink.put(c);
} |
What I meant is that logic could be optimized .
|
Thx for your detailed explanation. I will modify it today. |
LIKE
and ILIKE
operator
Regarding this issue: #2623 (comment) by @bziobrowski
Feature: Enable the backslash escape before wildcards
_
and%
to make them literal. Even number of backslashes will not make them literal.Test cases explained as follows: