This is an automated email from the ASF dual-hosted git repository.
mbudiu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 3217321149 [CALCITE-6180] Append possibility to escape backslash in
LIKE with ESCAPE operator
3217321149 is described below
commit 321732114993090fa7c87a67b1026d2d4b86b907
Author: zstan <[email protected]>
AuthorDate: Wed Dec 27 11:42:38 2023 +0300
[CALCITE-6180] Append possibility to escape backslash in LIKE with ESCAPE
operator
---
core/src/main/java/org/apache/calcite/runtime/Like.java | 3 +++
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java | 3 +++
2 files changed, 6 insertions(+)
diff --git a/core/src/main/java/org/apache/calcite/runtime/Like.java
b/core/src/main/java/org/apache/calcite/runtime/Like.java
index ac074afa3d..865efcc8d3 100644
--- a/core/src/main/java/org/apache/calcite/runtime/Like.java
+++ b/core/src/main/java/org/apache/calcite/runtime/Like.java
@@ -96,6 +96,9 @@ public class Like {
|| (nextChar == escapeChar)) {
javaPattern.append(nextChar);
i++;
+ } else if (nextChar == '\\') {
+ javaPattern.append("\\\\");
+ i++;
} else {
throw invalidEscapeSequence(sqlPattern, i);
}
diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
index 8385195980..8853610ca4 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -3591,6 +3591,9 @@ public class SqlOperatorTest {
@Test void testLikeEscape() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.LIKE, VmName.EXPAND);
+ f.checkBoolean("'a\\c' like 'a#\\c' escape '#'", true);
+ f.checkBoolean("'a\\\\c' like 'a#\\c' escape '#'", false);
+ f.checkBoolean("'a\\c' like 'a#\\\\c' escape '#'", false);
f.checkBoolean("'a_c' like 'a#_c' escape '#'", true);
f.checkBoolean("'axc' like 'a#_c' escape '#'", false);
f.checkBoolean("'a_c' like 'a\\_c' escape '\\'", true);