Skip to content

Commit e000389

Browse files
authored
More esql index resolution tests (#135619)
1 parent 72da17c commit e000389

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,19 @@ public void testDoesNotResolveMissingIndex() {
105105
}
106106

107107
public void testDoesNotResolveEmptyPattern() {
108+
assertAcked(client().admin().indices().prepareCreate("data"));
109+
indexRandom(true, "data", 1);
110+
108111
expectThrows(
109112
VerificationException.class,
110113
containsString("Unknown index [index-*]"),
111-
() -> run(syncEsqlQueryRequest().query("FROM index-*"))
114+
() -> run(syncEsqlQueryRequest().query("FROM index-* METADATA _index"))
112115
);
116+
117+
try (var response = run(syncEsqlQueryRequest().query("FROM data,index-* METADATA _index"))) {
118+
assertOk(response);
119+
assertResultConcreteIndices(response, "data");
120+
}
113121
}
114122

115123
public void testDoesNotResolveClosedIndex() {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.plugin;
9+
10+
import org.elasticsearch.cluster.metadata.IndexMetadata;
11+
import org.elasticsearch.common.settings.Settings;
12+
import org.elasticsearch.index.IndexMode;
13+
import org.elasticsearch.index.IndexSettings;
14+
import org.elasticsearch.xpack.esql.VerificationException;
15+
import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase;
16+
import org.elasticsearch.xpack.esql.action.EsqlQueryResponse;
17+
18+
import java.util.Map;
19+
20+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
21+
import static org.elasticsearch.xpack.esql.action.EsqlQueryRequest.syncEsqlQueryRequest;
22+
import static org.hamcrest.Matchers.containsString;
23+
import static org.hamcrest.Matchers.equalTo;
24+
25+
public class LookupIndexResolutionIT extends AbstractEsqlIntegTestCase {
26+
27+
public void testResolvesConcreteIndex() {
28+
createMainIndex("index-1");
29+
createLookupIndex("lookup");
30+
31+
try (var response = run(syncEsqlQueryRequest().query("FROM index-1 | LOOKUP JOIN lookup ON language_code"))) {
32+
assertOk(response);
33+
}
34+
}
35+
36+
public void testResolvesAlias() {
37+
createMainIndex("index-1");
38+
createLookupIndex("lookup");
39+
assertAcked(
40+
client().admin().indices().prepareAliases(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).addAlias("lookup", "lookup-alias")
41+
);
42+
43+
try (var response = run(syncEsqlQueryRequest().query("FROM index-1 | LOOKUP JOIN lookup-alias ON language_code"))) {
44+
assertOk(response);
45+
}
46+
}
47+
48+
public void testDoesNotResolveMissingIndex() {
49+
createMainIndex("index-1");
50+
51+
expectThrows(
52+
VerificationException.class,
53+
containsString("Unknown index [fake-lookup]"),
54+
() -> run(syncEsqlQueryRequest().query("FROM index-1 | LOOKUP JOIN fake-lookup ON language_code"))
55+
);
56+
}
57+
58+
private static void assertOk(EsqlQueryResponse response) {
59+
assertThat(response.isPartial(), equalTo(false));
60+
}
61+
62+
private void createMainIndex(String name) {
63+
assertAcked(client().admin().indices().prepareCreate(name));
64+
indexRandom(true, false, prepareIndex(name).setSource(Map.of("id", randomIdentifier(), "language_code", 1)));
65+
}
66+
67+
private void createLookupIndex(String name) {
68+
assertAcked(
69+
client().admin()
70+
.indices()
71+
.prepareCreate(name)
72+
.setSettings(
73+
Settings.builder().put(IndexSettings.MODE.getKey(), IndexMode.LOOKUP).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
74+
)
75+
);
76+
indexRandom(true, false, prepareIndex(name).setSource(Map.of("language_code", 1, "language", "english")));
77+
}
78+
}

0 commit comments

Comments
 (0)