0
votes

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
What I'm not undertstanding, and what would be important to know, is how many apple and banana and orange events are we comparing i.e. all possible ones? And do they arrive completely unordered or ordered? And what should trigger output, the arrival of an apple only or the arrival of any of the events? - user3613754
Hey, thanks for your reply. There are only one apple, one banana and one orange event seperately. They will come unordered. Output should be triggered if more than one of them(apple, banana or orange) have attributes eatable as true at almost the same time. - Narsu

1 Answers

0
votes

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