Skip to content

Commit 978db27

Browse files
Fix NPE on missing event queries (#103611) (#103619)
1 parent 3a5a2af commit 978db27

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

docs/changelog/103611.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 103611
2+
summary: Fix NPE on missing event queries
3+
area: EQL
4+
type: bug
5+
issues:
6+
- 103608

x-pack/plugin/eql/qa/common/src/main/resources/test_missing_events.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,16 @@ join_keys = ["foo", "foo",
385385
"foo", "foo",
386386
"baz", "baz"]
387387

388+
[[queries]]
389+
name = "interleaved_3_missing"
390+
query = '''
391+
sequence with maxspan=1h
392+
![ test1 where tag == "foobar" ]
393+
[ test1 where tag == "normal" ]
394+
![ test1 where tag == "foobar" ]
395+
[ test1 where tag == "normal" ]
396+
![ test1 where tag == "foobar" ]
397+
'''
398+
expected_event_ids = [-1, 1, -1, 2, -1,
399+
-1, 2, -1, 4, -1]
400+

x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/execution/sequence/Sequence.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ public class Sequence implements Comparable<Sequence>, Accountable {
3232

3333
private final SequenceKey key;
3434
private final Match[] matches;
35+
private int firstStage;
3536
private int currentStage = 0;
3637

3738
@SuppressWarnings({ "rawtypes", "unchecked" })
38-
public Sequence(SequenceKey key, int stages, Ordinal ordinal, HitReference firstHit) {
39+
public Sequence(SequenceKey key, int stages, int firstStage, Ordinal ordinal, HitReference firstHit) {
3940
Check.isTrue(stages >= 2, "A sequence requires at least 2 criteria, given [{}]", stages);
4041
this.key = key;
4142
this.matches = new Match[stages];
42-
this.matches[0] = new Match(ordinal, firstHit);
43+
this.matches[firstStage] = new Match(ordinal, firstHit);
44+
this.firstStage = firstStage;
45+
this.currentStage = firstStage;
4346
}
4447

4548
public void putMatch(int stage, Ordinal ordinal, HitReference hit) {
@@ -56,7 +59,7 @@ public Ordinal ordinal() {
5659
}
5760

5861
public Ordinal startOrdinal() {
59-
return matches[0].ordinal();
62+
return matches[firstStage].ordinal();
6063
}
6164

6265
public List<HitReference> hits() {

x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/execution/sequence/SequenceMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ boolean match(int stage, Iterable<Tuple<KeyAndOrdinal, HitReference>> hits) {
168168

169169
if (isFirstPositiveStage(stage)) {
170170
log.trace("Matching hit {} - track sequence", ko.ordinal);
171-
Sequence seq = new Sequence(ko.key, numberOfStages, ko.ordinal, hit);
171+
Sequence seq = new Sequence(ko.key, numberOfStages, stage, ko.ordinal, hit);
172172
if (lastPositiveStage == stage) {
173173
tryComplete(seq);
174174
} else {

0 commit comments

Comments
 (0)