Skip to content

Commit 13b35e6

Browse files
assign new id to aliases created by ReplaceMissingFieldWithNull
1 parent 7626026 commit 13b35e6

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEsqlTestCase.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,24 @@ public void testDoubleParamsWithLookupJoin() throws IOException {
986986
);
987987
}
988988

989+
public void testMultipleBatchesWithLookupJoin() throws IOException {
990+
// create 20 indices to trigger multiple batches of data node planning and execution
991+
for (int i = 1; i <= 20; i++) {
992+
createIndex("idx" + i, false);
993+
}
994+
bulkLoadTestDataLookupMode(10);
995+
var query = requestObjectBuilder().query(format(null, "from * | lookup join {} on integer | sort integer", testIndexName()));
996+
Map<String, Object> result = runEsql(query);
997+
var columns = as(result.get("columns"), List.class);
998+
assertEquals(20, columns.size());
999+
var values = as(result.get("values"), List.class);
1000+
assertEquals(10, values.size());
1001+
// clean up
1002+
for (int i = 1; i <= 20; i++) {
1003+
assertThat(deleteIndex("idx" + i).isAcknowledged(), is(true));
1004+
}
1005+
}
1006+
9891007
private void validateResultsOfDoubleParametersForIdentifiers(RequestObjectBuilder query) throws IOException {
9901008
Map<String, Object> result = runEsql(query);
9911009
Map<String, String> colA = Map.of("name", "boolean", "type", "boolean");

x-pack/plugin/esql/qa/testFixtures/src/main/resources/lookup-join.csv-spec

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,3 +1452,29 @@ emp_no:integer | language_code:integer | language_name:keyword
14521452
10092 | 1 | English
14531453
10093 | 3 | Spanish
14541454
;
1455+
1456+
multipleBatches
1457+
required_capability: join_lookup_v12
1458+
required_capability: remove_redundant_sort
1459+
1460+
from *
1461+
| dissect street "%{height_range} %{MNyXV}"
1462+
| rename env AS kxpCK, pod AS etUHW, language_code AS city.country.continent.planet.galaxy
1463+
| rename city.country.continent.planet.name as message
1464+
| lookup join message_types_lookup on message
1465+
| rename languages.int as language_code
1466+
| lookup join languages_lookup on language_code
1467+
| rename language_code as language_code
1468+
| lookup join languages_lookup on language_code
1469+
| stats c = count(*) by language_code
1470+
| sort language_code
1471+
;
1472+
1473+
c:long | language_code:long
1474+
15 | 1
1475+
19 | 2
1476+
17 | 3
1477+
18 | 4
1478+
21 | 5
1479+
6571 | null
1480+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/local/ReplaceMissingFieldWithNull.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ else if (plan instanceof Project project) {
8181
Alias nullAlias = nullLiteral.get(f.dataType());
8282
// save the first field as null (per datatype)
8383
if (nullAlias == null) {
84-
Alias alias = new Alias(f.source(), f.name(), Literal.of(f, null), f.id());
84+
Alias alias = joinAttributes.isEmpty()
85+
? new Alias(f.source(), f.name(), Literal.of(f, null), f.id())
86+
: new Alias(f.source(), f.name(), Literal.of(f, null));
8587
nullLiteral.put(dt, alias);
8688
projection = alias.toAttribute();
8789
}

0 commit comments

Comments
 (0)