Skip to content

Commit 0346762

Browse files
Do not mention asterisk as an invalid char
1 parent 816fcc1 commit 0346762

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/IdentifierBuilder.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,18 @@ private static void resolveAndValidateIndex(String index, EsqlBaseParser.IndexPa
304304
if (hasSeenStar && hasExclusion) {
305305
return;
306306
}
307-
throw new ParsingException(e, source(ctx), e.getMessage());
307+
308+
InvalidIndexNameException errorToThrow = e;
309+
/*
310+
* We only modify this particular message because it mentions '*' as an invalid char.
311+
* However, we do allow asterisk in the index patterns: wildcarded patterns. Let's not
312+
* mislead the user by mentioning this char in the error message.
313+
*/
314+
if (e.getMessage().contains("must not contain the following characters")) {
315+
errorToThrow = new InvalidIndexNameException(index, e.getMessage().replace("'*',", ""));
316+
}
317+
318+
throw new ParsingException(errorToThrow, source(ctx), errorToThrow.getMessage());
308319
}
309320
}
310321

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,7 @@ public void testInvalidPatternsWithIntermittentQuotes() {
32253225
// Construct the new invalid index pattern.
32263226
var remoteIndexWithInvalidChar = quote(randomIdentifier() + ":" + "foo" + randomInvalidChar + "bar");
32273227
var query = "FROM " + randomIndex + "," + remoteIndexWithInvalidChar;
3228-
expectError(query, "must not contain the following characters [' ','\"','*',',','/','<','>','?','\\','|']");
3228+
expectError(query, "must not contain the following characters [' ','\"',',','/','<','>','?','\\','|']");
32293229
}
32303230

32313231
// Colon outside a quoted string should result in an ANTLR error: a comma is expected.

0 commit comments

Comments
 (0)