Skip to content

Commit faf18ef

Browse files
authored
Test more resolution cases (#135763)
1 parent bd6f6fd commit faf18ef

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/IndexResolutionIT.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.elasticsearch.common.util.CollectionUtils;
1919
import org.elasticsearch.datastreams.DataStreamsPlugin;
2020
import org.elasticsearch.index.IndexNotFoundException;
21+
import org.elasticsearch.index.query.MatchAllQueryBuilder;
22+
import org.elasticsearch.index.query.MatchNoneQueryBuilder;
2123
import org.elasticsearch.plugins.Plugin;
2224
import org.elasticsearch.xpack.esql.VerificationException;
2325
import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase;
@@ -96,11 +98,24 @@ public void testResolvesPattern() {
9698
}
9799
}
98100

99-
public void testDoesNotResolveMissingIndex() {
101+
public void testResolvesExclusionPattern() {
102+
assertAcked(client().admin().indices().prepareCreate("index-1"));
103+
indexRandom(true, "index-1", 1);
104+
assertAcked(client().admin().indices().prepareCreate("index-2"));
105+
indexRandom(true, "index-2", 1);
106+
107+
try (var response = run(syncEsqlQueryRequest().query("FROM index*,-index-2 METADATA _index"))) {
108+
assertOk(response);
109+
assertResultConcreteIndices(response, "index-1");// excludes concrete index from pattern
110+
}
111+
try (var response = run(syncEsqlQueryRequest().query("FROM index*,-*2 METADATA _index"))) {
112+
assertOk(response);
113+
assertResultConcreteIndices(response, "index-1");// excludes pattern from pattern
114+
}
100115
expectThrows(
101116
VerificationException.class,
102-
containsString("Unknown index [no-such-index]"),
103-
() -> run(syncEsqlQueryRequest().query("FROM no-such-index"))
117+
containsString("Unknown index [index-*,-*]"),
118+
() -> run(syncEsqlQueryRequest().query("FROM index-*,-* METADATA _index")) // exclude all resolves to empty
104119
);
105120
}
106121

@@ -120,6 +135,14 @@ public void testDoesNotResolveEmptyPattern() {
120135
}
121136
}
122137

138+
public void testDoesNotResolveUnknownIndex() {
139+
expectThrows(
140+
VerificationException.class,
141+
containsString("Unknown index [no-such-index]"),
142+
() -> run(syncEsqlQueryRequest().query("FROM no-such-index"))
143+
);
144+
}
145+
123146
public void testDoesNotResolveClosedIndex() {
124147
assertAcked(client().admin().indices().prepareCreate("index-1"));
125148
indexRandom(true, "index-1", 1);
@@ -219,6 +242,20 @@ public void testPartialResolution() {
219242
);
220243
}
221244

245+
public void testResolutionWithFilter() {
246+
assertAcked(client().admin().indices().prepareCreate("data"));
247+
indexRandom(true, "data", 1);
248+
249+
try (var response = run(syncEsqlQueryRequest().query("FROM data METADATA _index").filter(new MatchAllQueryBuilder()))) {
250+
assertOk(response);
251+
assertResultConcreteIndices(response, "data");
252+
}
253+
try (var response = run(syncEsqlQueryRequest().query("FROM data METADATA _index").filter(new MatchNoneQueryBuilder()))) {
254+
assertOk(response);
255+
assertResultConcreteIndices(response);
256+
}
257+
}
258+
222259
private static void assertOk(EsqlQueryResponse response) {
223260
assertThat(response.isPartial(), equalTo(false));
224261
}

0 commit comments

Comments
 (0)