浏览代码

SQL: Improve parser error message for `ESCAPE` (#63616)

Mentions the list of wildchars in case a wildchar is used as an
`ESCAPE` character.

Relates #63428
Andras Palinkas 5 年之前
父节点
当前提交
74cbcf871e

+ 2 - 1
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/ExpressionBuilder.java

@@ -283,7 +283,8 @@ abstract class ExpressionBuilder extends IdentifierBuilder {
                 escape = escapeString.charAt(0);
                 // these chars already have a meaning
                 if (escape == '%' || escape == '_') {
-                    throw new ParsingException(source(escapeCtx.escape), "Char [{}] cannot be used for escaping", escape);
+                    throw new ParsingException(source(escapeCtx.escape),
+                            "Char [{}] cannot be used for escaping as it's one of the wildcard chars [%_]", escape);
                 }
                 // lastly validate that escape chars (if present) are followed by special chars
                 for (int i = 0; i < pattern.length(); i++) {

+ 2 - 2
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/parser/LikeEscapingParsingTests.java

@@ -74,9 +74,9 @@ public class LikeEscapingParsingTests extends ESTestCase {
 
     public void testEscapingWildcards() {
         assertThat(error("'string' ESCAPE '%'"),
-                is("line 1:27: Char [%] cannot be used for escaping"));
+                is("line 1:27: Char [%] cannot be used for escaping as it's one of the wildcard chars [%_]"));
         assertThat(error("'string' ESCAPE '_'"),
-            is("line 1:27: Char [_] cannot be used for escaping"));
+            is("line 1:27: Char [_] cannot be used for escaping as it's one of the wildcard chars [%_]"));
     }
 
     public void testCanUseStarWithoutEscaping() {