I have two event types (A and B). I would like to write a pattern which detects every B event which comes after A event with the same id: every A -> B (A.id = B.id)
. However, it should be distinct ids. In other words, the pattern should ignore all A events with the same id after the first one until the above expression is true, means B event with the same id comes.
For example, Assume this is an event stream:
1. A (id: 1); 2. A(id: 2); 3. A (id: 3); 4. A(id: 1); 5. A (id: 2); 6. B (id: 1); 7. B (id: 2); 8. A (id: 1); 9. B(id: 3); 10. A (id: 1); 11. B (id: 1)
The pattern should ignore event No4 as it has the same id with event No1. When the event No6 comes, the pattern should match 1. A (id: 1) -> 6. B (id: 1)
. Then, the pattern should allow new A event with id=1. So event No8 should not be ignored, but event No10 should be ignored. When event No11 comes, the pattern should match again 8. A(id: 1) -> 11. B(id: 1)
.
Besides, event No2 should match with event No7 and event No3 should match event No9.
I have tried to use EVERY-DISTINCT(A.id) A -> B (A.id=B.id)
, but it ignores all A events with the same id after the first one. Then I tried EVERY (A -> B (A.id = B.id))
, but it didn't work either as it ignores all A events regardless of id until B event with the same id comes.
You can have every A -> B (A.id = B.id)
statement within PATTERN
statement and add additionally add @SuppressOverlappingMatches
right after PATTERN
keyword.
Complete statement will be something like this:
SELECT b.id FROM PATTERN @SuppressOverlappingMatches [every a=A -> b=B (a.id = b.id)]