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.