Skip to content

Commit f10b9ff

Browse files
authored
Test subquery index resolution (elastic#138079)
1 parent 4249342 commit f10b9ff

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,27 +229,35 @@ public void testUnavailableIndex() {
229229

230230
public void testPartialResolution() {
231231
assertAcked(client().admin().indices().prepareCreate("index-1"));
232-
assertAcked(client().admin().indices().prepareCreate("index-2"));
233-
indexRandom(true, "index-2", 1);
232+
indexRandom(true, "index-1", 1);
234233

235-
try (var response = run(syncEsqlQueryRequest().query("FROM index-1,nonexisting-1"))) {
236-
assertOk(response); // okay when present index is empty
237-
}
238234
expectThrows(
239235
IndexNotFoundException.class,
240236
equalTo("no such index [nonexisting-1]"), // fails when present index is non-empty
241-
() -> run(syncEsqlQueryRequest().query("FROM index-2,nonexisting-1"))
237+
() -> run(syncEsqlQueryRequest().query("FROM index-1,nonexisting-1"))
242238
);
243239
expectThrows(
244240
IndexNotFoundException.class,
245241
equalTo("no such index [nonexisting-1]"), // fails when present index is non-empty even if allow_partial=true
246-
() -> run(syncEsqlQueryRequest().query("FROM index-2,nonexisting-1").allowPartialResults(true))
242+
() -> run(syncEsqlQueryRequest().query("FROM index-1,nonexisting-1").allowPartialResults(true))
247243
);
248244
expectThrows(
249245
IndexNotFoundException.class,
250246
equalTo("no such index [nonexisting-1]"), // only the first missing index is reported
251-
() -> run(syncEsqlQueryRequest().query("FROM index-2,nonexisting-1,nonexisting-2"))
247+
() -> run(syncEsqlQueryRequest().query("FROM index-1,nonexisting-1,nonexisting-2"))
252248
);
249+
250+
assertAcked(client().admin().indices().prepareCreate("index-2").setMapping("field", "type=keyword"));
251+
expectThrows(
252+
IndexNotFoundException.class,
253+
equalTo("no such index [nonexisting-1]"), // fails when present index has no documents and non-empty mapping
254+
() -> run(syncEsqlQueryRequest().query("FROM index-2,nonexisting-1"))
255+
);
256+
257+
assertAcked(client().admin().indices().prepareCreate("index-3"));
258+
try (var response = run(syncEsqlQueryRequest().query("FROM index-3,nonexisting-1"))) {
259+
assertOk(response); // passes when the present index has no fields and no documents
260+
}
253261
}
254262

255263
public void testResolutionWithFilter() {
@@ -266,6 +274,18 @@ public void testResolutionWithFilter() {
266274
}
267275
}
268276

277+
public void testSubqueryResolution() {
278+
assertAcked(client().admin().indices().prepareCreate("index-1"));
279+
indexRandom(true, "index-1", 1);
280+
assertAcked(client().admin().indices().prepareCreate("index-2"));
281+
indexRandom(true, "index-2", 1);
282+
283+
try (var response = run(syncEsqlQueryRequest().query("FROM index-1, (FROM index-2 METADATA _index) METADATA _index"))) {
284+
assertOk(response);
285+
assertResultConcreteIndices(response, "index-1", "index-2");
286+
}
287+
}
288+
269289
private static void assertOk(EsqlQueryResponse response) {
270290
assertThat(response.isPartial(), equalTo(false));
271291
}

0 commit comments

Comments
 (0)