Skip to content

Commit 2e638ec

Browse files
committed
Fix tests
1 parent f702160 commit 2e638ec

File tree

3 files changed

+9
-4
lines changed
  • x-pack/plugin/esql

3 files changed

+9
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fork1 | 10081 | null | null | null
161161
fork2 | 10081 | null | null | null
162162
fork2 | 10087 | null | null | null
163163
fork3 | null | 100 | 10100 | 10001
164-
fork4 | null | null | null | null
164+
fork4 | null | 100 | 10001 | null
165165
;
166166

167167
forkWithDrop-Ignore
@@ -223,8 +223,8 @@ FROM employees
223223
_fork:keyword | emp_no:integer | x:keyword | y:keyword | z:keyword | w:keyword
224224
fork1 | 10048 | Florian | 10048 | Syrotiuk | null
225225
fork1 | 10081 | Zhongwei | 10081 | Rosen | null
226-
fork2 | 10048 | null | null | null | Florian
227-
fork2 | 10081 | null | null | null | Zhongwei
226+
fork2 | 10048 | Syrotiuk | 10048 | null | Florian
227+
fork2 | 10081 | Rosen | 10081 | null | Zhongwei
228228
;
229229

230230
forkWithMixOfCommands

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ public void testWithEvalDifferentOutputs() {
521521
| FORK ( EVAL a = 1 )
522522
( EVAL b = 2 )
523523
| KEEP a, b, _fork
524+
| SORT _fork, a
524525
""";
525526
try (var resp = run(query)) {
526527
assertColumnNames(resp.columns(), List.of("a", "b", "_fork"));
@@ -533,6 +534,7 @@ public void testWithStatsSimple() {
533534
| FORK (STATS x=COUNT(*), y=VALUES(id))
534535
(WHERE id == 2)
535536
| KEEP _fork, x, y, id
537+
| SORT _fork, id
536538
""";
537539
try (var resp = run(query)) {
538540
assertColumnNames(resp.columns(), List.of("_fork", "x", "y", "id"));

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,10 @@ private LogicalPlan resolveFork(Fork fork, AnalyzerContext context) {
706706
}
707707

708708
List<String> subPlanColumns = logicalPlan.output().stream().map(Attribute::name).collect(Collectors.toList());
709-
if (subPlanColumns.equals(forkColumns) == false) {
709+
// We need to add an explicit Keep even if the outputs align
710+
// This is because at the moment the sub plans are executed and optimized separately and the output might change
711+
// during optimizations. Once we add streaming we might not need to add a Keep when the outputs already align.
712+
if (logicalPlan instanceof Keep == false || subPlanColumns.equals(forkColumns) == false) {
710713
changed = true;
711714
List<Attribute> newOutput = new ArrayList<>();
712715
for (String attrName : forkColumns) {

0 commit comments

Comments
 (0)