Skip to content

Commit 54d3104

Browse files
EQL: better error message for sequences with only one clause plus UNTIL (#132638) (#132792)
1 parent d62583c commit 54d3104

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

docs/changelog/132638.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 132638
2+
summary: Better error message for sequences with only one clause plus UNTIL
3+
area: EQL
4+
type: bug
5+
issues: []

x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/parser/LogicalPlanBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ public Sequence visitSequence(SequenceContext ctx) {
330330

331331
// until is already parsed through sequenceTerm() above
332332
if (ctx.until != null) {
333+
if (queries.size() == 2) {
334+
throw new ParsingException(source, "A sequence requires a minimum of 2 queries (excluding UNTIL clause), found [1]");
335+
}
333336
until = queries.remove(queries.size() - 1);
334337
} else {
335338
until = defaultUntil(source);

x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/planner/QueryTranslatorFailTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,17 @@ public void testSequenceWithTooLittleQueries() throws Exception {
261261
assertEquals("1:2: A sequence requires a minimum of 2 queries, found [1]", s);
262262
}
263263

264+
public void testSequenceWithTooLittleQueriesWithUntil() throws Exception {
265+
String s = errorParsing("sequence [any where true] until [any where true]");
266+
assertEquals("1:2: A sequence requires a minimum of 2 queries (excluding UNTIL clause), found [1]", s);
267+
plan("sequence [any where true] [any where true] until [any where true]");
268+
}
269+
270+
public void testSequenceWithOnlyMissingEventsAndUntil() throws Exception {
271+
String s = errorParsing("sequence with maxspan=1h ![process where true] until [process where true]");
272+
assertEquals("1:2: A sequence requires a minimum of 2 queries (excluding UNTIL clause), found [1]", s);
273+
}
274+
264275
public void testSequenceWithIncorrectOption() throws Exception {
265276
EqlClientException e = expectThrows(EqlClientException.class, () -> plan("sequence [any where true] with repeat=123"));
266277
String msg = e.getMessage();

0 commit comments

Comments
 (0)