0

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

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 Oct 28 '20 at 13:04
  • duplicate of https://stackoverflow.com/questions/64244157/esper-nesper-epl-event-statement – user650839 Oct 28 '20 at 13:38
  • 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 Oct 28 '20 at 19:23

1 Answers1

0

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
user650839
  • 2,594
  • 1
  • 13
  • 9
user3613754
  • 816
  • 1
  • 5
  • 5
  • Hello, thanks for your reply and the solution. This is a solution for Esper(java) right? Is it possible to implement this in NEsper(C#)? I'm working in .Net environment. Another point is that, the pattern should be catched if more than one events(fruits in this case) are eatable at almost the same time. If only one is eatable, it should be ignored. I know the statement 'select * from ...' is an EPL statement. these three 'create schama ...' are also EPL statement? – Narsu Nov 05 '20 at 14:30