Esper query for A followed by B immediately without any other events in between (no matter which event)

187 Views Asked by At

I have to implement the rule, that if A occurs, B hast to occur next without any event in between. Usually I could do this by just using the patter:

A->(B and not ...)

But I have to implement it very dynamical. That means that I don't know all of the possible events in advance. Does anybody know how i could implement this? I guess I need something like:

A->(B and not any other event)

Thank you for your help. :)

2

There are 2 best solutions below

1
On

See this other ticket Esper statement to check, if A is followed by B without any other As in between It explains the match-recognize.

Here are a few path you can go down in respect to many types of events.

Create-schema with inherits plus typeof-function

create schema Parent();
create schema A() inherits Parent;
create schema B() inherits Parent;
// now you can treat all events as Parent events
select * from pattern[p=Parent(typeof(p)='A') -> ...] // or match-recognize

Variant stream

create variant schema AnyEventStream as *; // this stream can hold any type of event
insert into AnyEventStream select * from A;
insert into AnyEventStream select * from B;
select * from pattern[p=AnyEventStream(typeof(p)='A') -> ...]  // or match-recognize

Normalize with insert-into

insert into CombinedStream select 'a' as type from A;
insert into CombinedStream select 'b' as type from B;
// now match on CombinedStream
select * from pattern[p=CombinedStream(type='A') -> ...]  // or match-recognize

Make each event a column

create schema CombinedStream(col java.lang.Object);
insert into CombinedStream select a as col from A as a;
insert into CombinedStream select b as col from B as b;
select * from pattern[p=CombinedStream(typeof(col)='...') -> ...]  // or match-recognize

You can probably combine some of these approaches. You can also use Java interfaces and abstract classes in replacement of "inherits" since the type system recognizes superclasses/interfaces.

0
On

Thank you very for your reply. I tried your suggestions and making each event a column seams to work pretty well for me. My only problem is, that i have to get access to the properties of each event to check some conditions. For example:

select * from CombinedStream.win:length(1) where typeof(col)='MachineFailureEvent' and id=1;

Until the id-check everything works fine, but the compiler tells me, that the property id is not valid in this stream.. do you have in idea? Tanke you :)