Esper / NEsper EPL statement

137 views Asked by At

I'm trying to define NEsper EPL event statement for the following situation. I have 3 events - for example apple, banana and orange. They all have attributes - (bool) eatable, (datetime) timestamp. I want to catch the pattern, if more than one events are eatable - true at almost the same timestamp. If only one of them is eatable (only one has eatable true) at almost same timestamp(time difference for example 1s) it is ok. But if they have 2 or more eatable true at almost the same timestamp(time difference for example 1seconds) the pattern should be captured. How can I define the EPL statement for this situation? Thanks for any advice.

Best regards Narsu

1

There are 1 answers

1
user3613754 On

Using long timestamp here since there is no such thing as "datetime" type for Java (perhaps there is for .NET).

Just change the where-clause for more elaborate criteria.

Instead of minus and Math#abs one could use "after" and "before" with boundaries but some simple arithmetic seems easier here.

create schema Apple(eatable boolean, ts long); 
create schema Banana(eatable boolean, ts long); 
create schema Orange(eatable boolean, ts long); 

select * from Apple#lastevent as a, Banana#lastevent as b, Orange#lastevent as o
where {a.eatable, b.eatable, o.eatable}.countOf(v=>v) = 1 // exactly one is eatable
and (Math.abs(a.ts - b.ts)+Math.abs(b.ts - o.ts)) < 1000000