Skip to content

Commit 0cc5580

Browse files
Apply suggestions from review
1 parent b6339e7 commit 0cc5580

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ protected static void validateClusterString(String clusterString, EsqlBaseParser
132132
/**
133133
* Takes the parsed constituent strings and validates them.
134134
* @param clusterString Name of the remote cluster. Can be null.
135-
* @param indexPattern Name of the index or pattern; can also have multiple patterns in case of quoting, e.g. {@code FROM """index*,-index1"""}.
135+
* @param indexPattern Name of the index or pattern; can also have multiple patterns in case of quoting,
136+
* e.g. {@code FROM """index*,-index1"""}.
136137
* @param selectorString Selector string, i.e. "::data" or "::failures". Can be null.
137138
* @param ctx Index Pattern Context for generating error messages with offsets.
138139
* @param hasSeenStar If we've seen an asterisk so far.
@@ -158,7 +159,7 @@ private static void validate(
158159
String[] patterns;
159160
if (clusterString == null && selectorString == null) {
160161
// Pattern could be quoted or is singular like "index_name".
161-
patterns = indexPattern.split(",");
162+
patterns = indexPattern.split(",", -1);
162163
} else {
163164
// Either of cluster string or selector string is present. Pattern is unquoted.
164165
patterns = new String[] { indexPattern };
@@ -169,11 +170,11 @@ private static void validate(
169170
throwInvalidIndexNameException(indexPattern, BLANK_INDEX_ERROR_MESSAGE, ctx);
170171
}
171172

172-
// Edge case: happens when all the index names in a pattern are empty.
173+
// Edge case: happens when all the index names in a pattern are empty like "FROM ",,,,,"".
173174
if (patterns.length == 0) {
174175
throwInvalidIndexNameException(indexPattern, BLANK_INDEX_ERROR_MESSAGE, ctx);
175176
} else if (patterns.length == 1) {
176-
// Pattern is an unquoted string.
177+
// Pattern is either an unquoted string or a quoted string with a single index (no comma sep).
177178
validateSingleIndexPattern(clusterString, patterns[0], selectorString, ctx, hasSeenStar);
178179
} else {
179180
/*

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,6 +3180,10 @@ public void testInvalidFromPatterns() {
31803180
expectError(randomFrom(sourceCommands) + " \",,, \"", indexIsBlank);
31813181
expectError(randomFrom(sourceCommands) + " \", , ,,\"", indexIsBlank);
31823182
expectError(randomFrom(sourceCommands) + " \",,,\",*", indexIsBlank);
3183+
expectError(randomFrom(sourceCommands) + " \"*,\"", indexIsBlank);
3184+
expectError(randomFrom(sourceCommands) + " \"*,,,\"", indexIsBlank);
3185+
expectError(randomFrom(sourceCommands) + " \"index1,,,,\"", indexIsBlank);
3186+
expectError(randomFrom(sourceCommands) + " \"index1,index2,,\"", indexIsBlank);
31833187
expectError(randomFrom(sourceCommands) + " \"index1,<-+^,index2\",*", "must not contain the following characters");
31843188
expectError(randomFrom(sourceCommands) + " \"\",*", indexIsBlank);
31853189
expectError(randomFrom(sourceCommands) + " \"*: ,*,\"", indexIsBlank);

0 commit comments

Comments
 (0)