Skip to content

Commit dff4f98

Browse files
author
Andras Palinkas
committed
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 (cherry picked from commit 74cbcf8)
1 parent 3c9f183 commit dff4f98

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ public LikePattern visitPattern(PatternContext ctx) {
283283
escape = escapeString.charAt(0);
284284
// these chars already have a meaning
285285
if (escape == '%' || escape == '_') {
286-
throw new ParsingException(source(escapeCtx.escape), "Char [{}] cannot be used for escaping", escape);
286+
throw new ParsingException(source(escapeCtx.escape),
287+
"Char [{}] cannot be used for escaping as it's one of the wildcard chars [%_]", escape);
287288
}
288289
// lastly validate that escape chars (if present) are followed by special chars
289290
for (int i = 0; i < pattern.length(); i++) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public void testEscapingTheEscapeCharacter() {
7474

7575
public void testEscapingWildcards() {
7676
assertThat(error("'string' ESCAPE '%'"),
77-
is("line 1:27: Char [%] cannot be used for escaping"));
77+
is("line 1:27: Char [%] cannot be used for escaping as it's one of the wildcard chars [%_]"));
7878
assertThat(error("'string' ESCAPE '_'"),
79-
is("line 1:27: Char [_] cannot be used for escaping"));
79+
is("line 1:27: Char [_] cannot be used for escaping as it's one of the wildcard chars [%_]"));
8080
}
8181

8282
public void testCanUseStarWithoutEscaping() {

0 commit comments

Comments
 (0)