Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/114271.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 114271
summary: "[ES|QL] Skip validating remote cluster index names in parser"
area: ES|QL
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;

import static org.elasticsearch.transport.RemoteClusterAware.REMOTE_CLUSTER_INDEX_SEPARATOR;
import static org.elasticsearch.transport.RemoteClusterAware.isRemoteIndexName;
import static org.elasticsearch.xpack.esql.core.util.StringUtils.EXCLUSION;
import static org.elasticsearch.xpack.esql.core.util.StringUtils.WILDCARD;
import static org.elasticsearch.xpack.esql.parser.ParserUtils.source;
Expand Down Expand Up @@ -61,11 +62,14 @@ public String visitIndexPattern(List<EsqlBaseParser.IndexPatternContext> ctx) {
Holder<Boolean> hasSeenStar = new Holder<>(false);
ctx.forEach(c -> {
String indexPattern = visitIndexString(c.indexString());
hasSeenStar.set(indexPattern.contains(WILDCARD) || hasSeenStar.get());
validateIndexPattern(indexPattern, c, hasSeenStar.get());
patterns.add(
c.clusterString() != null ? c.clusterString().getText() + REMOTE_CLUSTER_INDEX_SEPARATOR + indexPattern : indexPattern
);
String clusterString = c.clusterString() != null ? c.clusterString().getText() : null;
// 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) {
hasSeenStar.set(indexPattern.contains(WILDCARD) || hasSeenStar.get());
validateIndexPattern(indexPattern, c, hasSeenStar.get());
}
patterns.add(clusterString != null ? clusterString + REMOTE_CLUSTER_INDEX_SEPARATOR + indexPattern : indexPattern);
});
return Strings.collectionToDelimitedString(patterns, ",");
}
Expand All @@ -75,6 +79,9 @@ private static void validateIndexPattern(String indexPattern, EsqlBaseParser.Ind
String[] indices = indexPattern.split(",");
boolean hasExclusion = false;
for (String index : indices) {
if (isRemoteIndexName(index)) { // skip the validation if there is remote cluster
continue;
}
hasSeenStar = index.contains(WILDCARD) || hasSeenStar;
index = index.replace(WILDCARD, "").strip();
if (index.isBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,15 @@ void expectError(String query, List<QueryParam> params, String errorMessage) {
assertThat(e.getMessage(), containsString(errorMessage));
}

void expectInvalidIndexNameErrorWithLineNumber(String query, String arg, String lineNumber, String indexString) {
expectError(LoggerMessageFormat.format(null, query, arg), lineNumber + "Invalid index name [" + indexString);
void expectInvalidIndexNameErrorWithLineNumber(String query, String indexString, String lineNumber) {
if ((indexString.contains("|") || indexString.contains(" ")) == false) {
expectInvalidIndexNameErrorWithLineNumber(query, indexString, lineNumber, indexString);
}
expectInvalidIndexNameErrorWithLineNumber(query, "\"" + indexString + "\"", lineNumber, indexString);
}

void expectInvalidIndexNameErrorWithLineNumber(String query, String indexString, String lineNumber, String error) {
expectError(LoggerMessageFormat.format(null, query, indexString), lineNumber + "Invalid index name [" + error);
}

void expectDateMathErrorWithLineNumber(String query, String arg, String lineNumber, String error) {
Expand Down
Loading