问题
I have the two events: A and B. Everytime A occurs, B have to occur afterwards without any As in between. Has anybody got an idea, how to implement this? I thought about something like
pattern[every A -> A until B]
But this statement is true, even if A is followed B without any other As in between. But it should only be true in case of AAB or AAAAB and so on..
Thank you for your help.
回答1:
One possible solution is the pattern
A -> (A and not B)
Doing so the query is only true, when the rule is violated. But if it is fulfilled, I don't get any hint. Is there a better solution?
回答2:
Match-recognize pattern matching has immediately-followed-by-semantics. You could do something like this:
create schema A();
create schema B();
select * from pattern[every a=A or every b=B]
match_recognize (
measures p1 as a, p2 as b
pattern (p1 p2)
define
p1 as typeof(p1.a) = 'A',
p2 as typeof(p2.b) = 'B'
)
Or you could use an approach with insert-into.
insert into CombinedStream select id, 'a' as type from A;
insert into CombinedStream select id, 'b' as type from B;
select * from CombinedStream
match_recognize (
measures a as a, b as b
pattern (a b)
define
a as a.type = 'A',
b as b.type = 'B'
)
And when you want to go with EPL pattern langague that can also work. EPL patterns always add and remove from filter indexes and that can be less performant depending on how many incoming events are matched and unmatched/discarded (i.e. per-event-analysis versus need-in-a-haystack)
every A -> (B and not A) // read: every A followed by B and not A
来源:https://stackoverflow.com/questions/65267473/esper-statement-to-check-if-a-is-followed-by-b-without-any-other-as-in-between