Skip to content

Commit b3c1047

Browse files
committed
more tests
1 parent 59d98b2 commit b3c1047

File tree

2 files changed

+96
-5
lines changed

2 files changed

+96
-5
lines changed

x-pack/plugin/build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ tasks.named("yamlRestCompatTestTransform").configure({ task ->
9797
task.skipTest("esql/180_match_operator/match with functions", "Error message changed")
9898
task.skipTest("esql/180_match_operator/match within eval", "Error message changed")
9999
task.skipTest("esql/40_unsupported_types/semantic_text declared in mapping", "The semantic text field format changed")
100-
task.skipTest("esql/180_match_operator/match with disjunctions", "Disjunctions in full text functions work now")
100+
task.skipTest("esql/190_lookup_join/Alias as lookup index", "LOOKUP JOIN does not support index aliases for now")
101+
task.skipTest("esql/190_lookup_join/alias-repeated-alias", "LOOKUP JOIN does not support index aliases for now")
102+
task.skipTest("esql/190_lookup_join/alias-repeated-index", "LOOKUP JOIN does not support index aliases for now")
103+
task.skipTest("esql/190_lookup_join/alias-pattern-multiple", "LOOKUP JOIN does not support index aliases for now")
104+
task.skipTest("esql/190_lookup_join/alias-pattern-single", "LOOKUP JOIN does not support index aliases for now") task.skipTest("esql/180_match_operator/match with disjunctions", "Disjunctions in full text functions work now")
101105
task.skipTest("esql/130_spatial/values unsupported for geo_point", "Spatial types are now supported in VALUES aggregation")
102106
task.skipTest("esql/130_spatial/values unsupported for geo_point status code", "Spatial types are now supported in VALUES aggregation")
103107
// Expected deprecation warning to compat yaml tests:
@@ -129,8 +133,8 @@ tasks.named("yamlRestCompatTestTransform").configure({ task ->
129133
task.skipTest("esql/90_non_indexed/fetch", "Temporary until backported")
130134
task.skipTest("esql/63_enrich_int_range/Invalid age as double", "TODO: require disable allow_partial_results")
131135
task.skipTest("esql/191_lookup_join_on_datastreams/data streams not supported in LOOKUP JOIN", "Added support for aliases in JOINs")
132-
task.skipTest("esql/190_lookup_join/non-lookup index", "Error message changed")
133-
task.skipTest("esql/192_lookup_join_on_aliases/alias-pattern-multiple", "Error message changed")
136+
task.skipTest("esql/190_lookup_join/fails with non-lookup index", "Error message changed")
137+
task.skipTest("esql/192_lookup_join_on_aliases/fails when alias or pattern resolves to multiple", "Error message changed")
134138
})
135139

136140
tasks.named('yamlRestCompatTest').configure {

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

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.common.settings.Settings;
1313
import org.elasticsearch.test.junit.annotations.TestLogging;
1414
import org.elasticsearch.xpack.esql.VerificationException;
15+
import org.elasticsearch.xpack.esql.core.type.DataType;
1516

1617
import java.io.IOException;
1718
import java.util.List;
@@ -72,17 +73,43 @@ public void testLookupJoinAcrossClusters() throws IOException {
7273

7374
populateLookupIndex(LOCAL_CLUSTER, "values_lookup2", 5);
7475
populateLookupIndex(REMOTE_CLUSTER_1, "values_lookup2", 5);
75-
// FIXME: this currently does not work
7676
try (
7777
EsqlQueryResponse resp = runQuery(
7878
"FROM logs-*,c*:logs-* | EVAL lookup_key = v | LOOKUP JOIN values_lookup ON lookup_key "
79-
+ "| LOOKUP JOIN values_lookup2 ON lookup_tag",
79+
+ "| LOOKUP JOIN values_lookup2 ON lookup_key",
8080
randomBoolean()
8181
)
8282
) {
8383
List<List<Object>> values = getValuesList(resp);
8484
assertThat(values, hasSize(20));
85+
}
8586

87+
try (
88+
EsqlQueryResponse resp = runQuery(
89+
"FROM logs-*,c*:logs-* | EVAL lookup_key = v | LOOKUP JOIN values_lookup ON lookup_key "
90+
+ "| STATS c = count(*) BY lookup_name | SORT c",
91+
randomBoolean()
92+
)
93+
) {
94+
List<List<Object>> values = getValuesList(resp);
95+
// 0-9 + null + 16
96+
assertThat(values, hasSize(12));
97+
for (var row : values) {
98+
if (row.get(1) == null) {
99+
assertThat((Long) row.get(0), equalTo(5L)); // null
100+
} else {
101+
assertThat((String) row.get(1), containsString("lookup_"));
102+
if (row.get(1).equals("lookup_0")
103+
|| row.get(1).equals("lookup_1")
104+
|| row.get(1).equals("lookup_4")
105+
|| row.get(1).equals("lookup_9")) {
106+
// squares
107+
assertThat((Long) row.get(0), equalTo(2L));
108+
} else {
109+
assertThat((Long) row.get(0), equalTo(1L));
110+
}
111+
}
112+
}
86113
}
87114
}
88115

@@ -292,6 +319,40 @@ public void testLookupJoinIndexMode() throws IOException {
292319
);
293320
}
294321

322+
public void testLookupJoinFieldTypes() throws IOException {
323+
setupClusters(2);
324+
populateLookupIndex(LOCAL_CLUSTER, "values_lookup", 10);
325+
populateLookupIndexKeyword(REMOTE_CLUSTER_1, "values_lookup", 10);
326+
327+
setSkipUnavailable(REMOTE_CLUSTER_1, true);
328+
var ex = expectThrows(
329+
VerificationException.class,
330+
() -> runQuery("FROM logs-*,c*:logs-* | EVAL lookup_key = v | LOOKUP JOIN values_lookup ON lookup_key", randomBoolean())
331+
);
332+
assertThat(
333+
ex.getMessage(),
334+
containsString(
335+
"Cannot use field [lookup_key] due to ambiguities being mapped as [2] incompatible types:"
336+
+ " [keyword] in [cluster-a:values_lookup], [long] in [values_lookup]"
337+
)
338+
);
339+
340+
try (
341+
EsqlQueryResponse resp = runQuery(
342+
"FROM logs-*,c*:logs-* | EVAL lookup_name = v::keyword | LOOKUP JOIN values_lookup ON lookup_name",
343+
randomBoolean()
344+
)
345+
) {
346+
var columns = resp.columns();
347+
assertThat(columns, hasSize(9));
348+
var keyColumn = columns.stream().filter(c -> c.name().equals("lookup_key")).findFirst();
349+
assertTrue(keyColumn.isPresent());
350+
assertThat(keyColumn.get().type(), equalTo(DataType.UNSUPPORTED));
351+
assertThat(keyColumn.get().originalTypes(), hasItems("keyword", "long"));
352+
}
353+
354+
}
355+
295356
protected Map<String, Object> setupClustersAndLookups() throws IOException {
296357
var setupData = setupClusters(2);
297358
populateLookupIndex(LOCAL_CLUSTER, "values_lookup", 10);
@@ -325,6 +386,32 @@ protected void populateLookupIndex(String clusterAlias, String indexName, int nu
325386
client.admin().indices().prepareRefresh(indexName).get();
326387
}
327388

389+
protected void populateLookupIndexKeyword(String clusterAlias, String indexName, int numDocs) {
390+
Client client = client(clusterAlias);
391+
String tag = Strings.isEmpty(clusterAlias) ? "local" : clusterAlias;
392+
String field_tag = Strings.isEmpty(clusterAlias) ? "local_tag" : "remote_tag";
393+
assertAcked(
394+
client.admin()
395+
.indices()
396+
.prepareCreate(indexName)
397+
.setSettings(Settings.builder().put("index.mode", "lookup"))
398+
.setMapping(
399+
"lookup_key",
400+
"type=keyword",
401+
"lookup_name",
402+
"type=keyword",
403+
"lookup_tag",
404+
"type=keyword",
405+
field_tag,
406+
"type=keyword"
407+
)
408+
);
409+
for (int i = 0; i < numDocs; i++) {
410+
client.prepareIndex(indexName).setSource("lookup_key", i, "lookup_name", "lookup_" + i, "lookup_tag", tag, field_tag, i).get();
411+
}
412+
client.admin().indices().prepareRefresh(indexName).get();
413+
}
414+
328415
private static void assertCCSExecutionInfoDetails(EsqlExecutionInfo executionInfo) {
329416
assertNotNull(executionInfo);
330417
assertThat(executionInfo.overallTook().millis(), greaterThanOrEqualTo(0L));

0 commit comments

Comments
 (0)