Skip to content

Commit 9f2f4f2

Browse files
authored
Add friendly error message when using more than one FORK (#126599)
1 parent 94e8eb0 commit 9f2f4f2

File tree

2 files changed

+15
-0
lines changed
  • x-pack/plugin/esql/src

2 files changed

+15
-0
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/Fork.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ private static void checkFork(LogicalPlan plan, Failures failures) {
144144
}
145145
Fork fork = (Fork) plan;
146146

147+
fork.forEachDown(Fork.class, otherFork -> {
148+
if (fork == otherFork) {
149+
return;
150+
}
151+
152+
failures.add(Failure.fail(otherFork, "Only a single FORK command is allowed, but found multiple"));
153+
});
154+
147155
Map<String, DataType> outputTypes = fork.children()
148156
.getFirst()
149157
.output()

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,6 +3288,13 @@ public void testForkError() {
32883288
( WHERE emp_no > 2 | SORT emp_no | LIMIT 10 )
32893289
"""));
32903290
assertThat(e.getMessage(), containsString("aggregate function [COUNT(first_name)] not allowed outside STATS command"));
3291+
3292+
e = expectThrows(VerificationException.class, () -> analyze("""
3293+
FROM test
3294+
| FORK (EVAL a = 1) (EVAL a = 2)
3295+
| FORK (EVAL b = 3) (EVAL b = 4)
3296+
"""));
3297+
assertThat(e.getMessage(), containsString("Only a single FORK command is allowed, but found multiple"));
32913298
}
32923299

32933300
public void testValidRrf() {

0 commit comments

Comments
 (0)