Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8f324ae
Check if index patterns conform to valid format before validation
pawankartik-elastic Feb 13, 2025
1ddbce4
Update docs/changelog/122497.yaml
pawankartik-elastic Feb 13, 2025
46758cb
Let `validateClusterString()` look for `REMOTE_CLUSTER_INDEX_SEPARATOR`
pawankartik-elastic Feb 13, 2025
2f2ee85
Merge branch 'main' into pkar/index-pattern-check
pawankartik-elastic Feb 13, 2025
7ca6d70
Merge branch 'main' into pkar/index-pattern-check
pawankartik-elastic Apr 7, 2025
9dd96df
Mute 3 cases till further clarification and fix error string message
pawankartik-elastic Apr 7, 2025
0686c8f
Fix tests
pawankartik-elastic Apr 7, 2025
7c55d6c
Fix bug in breaking down indices
pawankartik-elastic Apr 8, 2025
2653377
Merge branch 'main' into pkar/index-pattern-check
pawankartik-elastic Apr 10, 2025
5832ff0
Tiny refactoring around how wildcard is processed and added tests
pawankartik-elastic Apr 10, 2025
6cdbf5a
[CI] Auto commit changes from spotless
Apr 10, 2025
c2160bb
Drop duplicated test cases and fix flaky-ness caused by quoting
pawankartik-elastic Apr 10, 2025
544171b
Set cluster string to `null` when it cannot be associated with an index
pawankartik-elastic Apr 11, 2025
133a7c7
Generate correct invalid patterns
pawankartik-elastic Apr 11, 2025
7da29d8
Merge branch 'main' into pkar/index-pattern-check
pawankartik-elastic Apr 11, 2025
5c70d51
Address review comments and don't break indices into its constituents
pawankartik-elastic Apr 16, 2025
7ad6ac3
Merge branch 'main' into pkar/index-pattern-check
pawankartik-elastic Jun 18, 2025
3058610
Adhere to the new grammar
pawankartik-elastic Jun 19, 2025
376126e
Merge branch 'main' into pkar/index-pattern-check
pawankartik-elastic Jun 19, 2025
1a43029
Update docs/changelog/122497.yaml
pawankartik-elastic Jun 19, 2025
8363b70
Update x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/…
pawankartik-elastic Jun 20, 2025
9c16afb
Apply suggestions from review
pawankartik-elastic Jun 23, 2025
8f9f519
Merge branch 'main' into pkar/index-pattern-check
pawankartik-elastic Jun 23, 2025
b6339e7
Apply suggestions from code review
pawankartik-elastic Jun 23, 2025
0cc5580
Apply suggestions from review
pawankartik-elastic Jun 23, 2025
816fcc1
Merge branch 'main' into pkar/index-pattern-check
pawankartik-elastic Jun 23, 2025
0346762
Do not mention asterisk as an invalid char
pawankartik-elastic Jun 25, 2025
9d275a5
Merge branch 'main' into pkar/index-pattern-check
pawankartik-elastic Jun 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/122497.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 122497
summary: Check if index patterns conform to valid format before validation
area: CCS
type: bug
issues: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently permits white spaces between separators and index name, like FROM "remote : idx" and FROM idx :: failures; it fails with less helpful error messages later down the line.

I think this is related to #129768, but not exactly the same. To avoid scope creep, we can tackle this in a follow-up or make it part of the other issue. I added a comment #129768 (comment) so we don't forget.

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ public String visitIndexPattern(List<EsqlBaseParser.IndexPatternContext> ctx) {
ctx.forEach(c -> {
String indexPattern = visitIndexString(c.indexString());
String clusterString = visitClusterString(c.clusterString());
// At this point, we run 2 kinds of checks. The first check is to ensure that this string adheres to the valid
// pattern format. The second check is to ensure that the parts of this string, i.e. the remote name, cluster name, and
// other aspects of them are valid. There's no point in running the second check if the first one fails.
// Should clusterString be non-null, validateClusterString() handles the required validation. So for now, look only at
// the indexPattern.
var maxSeparators = clusterString == null ? 1 : 0;
if (patternExceedsMaxIndexSeparators(indexPattern, maxSeparators)) {
throw new ParsingException(source(c), "Unexpected index separator in index pattern");
}
// skip validating index on remote cluster, because the behavior of remote cluster is not consistent with local cluster
// For example, invalid#index is an invalid index name, however FROM *:invalid#index does not return an error
if (clusterString == null) {
Expand Down Expand Up @@ -138,4 +147,20 @@ private static void validateIndexPattern(String indexPattern, EsqlBaseParser.Ind
private static String removeExclusion(String indexPattern) {
return indexPattern.charAt(0) == EXCLUSION.charAt(0) ? indexPattern.substring(1) : indexPattern;
}

private static boolean patternExceedsMaxIndexSeparators(String pattern, int maxAllowedSeparators) {
int seperatorsCount = 0;
boolean inDateTime = false;
for (char ch : pattern.toCharArray()) {
if (ch == '<') {
inDateTime = true;
} else if (ch == '>') {
inDateTime = false;
} else if (ch == REMOTE_CLUSTER_INDEX_SEPARATOR && inDateTime == false) {
seperatorsCount++;
}
}

return seperatorsCount > maxAllowedSeparators;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ public void testInvalidQuotingAsFromIndexPattern() {

expectError("FROM \"\"\"foo\"\"\"bar\"\"\"", ": mismatched input 'bar' expecting {<EOF>, '|', ',', 'metadata'}");
expectError("FROM \"\"\"foo\"\"\"\"\"\"bar\"\"\"", ": mismatched input '\"bar\"' expecting {<EOF>, '|', ',', 'metadata'}");
expectError("FROM remote:\"foo:bar\"", "Unexpected index separator in index patter");
expectError("FROM \"remote:foo:bar:baz\"", "Unexpected index separator in index patter");
}

public void testInvalidQuotingAsMetricsIndexPattern() {
Expand Down