0

I've been working with Esper recently and there's a feature I missed in the documentation but it might exist.

I would like to store some events until no one pops up for 15 sec, and when it happens release them all.

One query does exactly that, it's :

select rstream * from MyEvent.win:time_accum(15 sec)

I can add a condition on the MyEvent like

select rstream * from MyEvent where status = 'ALARM_END'.win:time_accum(15 sec)

And this perfectly works.

Now I would like to add a condition on the eventType attribute saying that :

if a new event is triggered with eventType xxxx but there is already an event with eventType xxxx in the window then don't add this new popping event to the window (and therefore don't stop the stopwatch from 0 to 15s).

Is there a way to do that ?

Thanks a lot !

EDIT :

Looking more deeply into my need and ESPER documentation, I think my need is more satisfied with

select * from MyEvent.win:time_length_batch(15 sec, 2)

I don't think I need rstream as I just want to accumulate either 1 or 2 elements and get them all-at-once in an array (of new Events it's fine).

However, is it possible to add a condition on the first (and the first only) MyEvent coming into the window ? It is status = 'ALARM_END'.

Tchak
  • 21
  • 6

1 Answers1

0

You may have a named window and check that before inserting.

// define named window
create window MyEventWindow#time_accum(15) as MyEvent;

// insert events that don't have 'xxx'
insert into MyEventWindow select * from MyEvent(eventType != 'xxx');

// insert events that have 'xxx' only if not already there
insert into MyEventWindow select * from MyEvent(eventType = 'xxx') 
  where not exists(select * from MyEventWindow where eventType='xxx');

// usual select
select rstream * from MyEventWindow;
user650839
  • 2,594
  • 1
  • 13
  • 9
  • Hello, thanks for your answer. I think I might have not been clear in my question. 'xxxx' is not supposed to be a fixed variable. – Tchak Oct 12 '17 at 08:55
  • Let's assume the current window has 3 events with eventTypes 'eT1', 'eT2', and 'eT3'. Then if a new event is triggered, it is added to the window only if its eventType is different from 'eT1', 'eT2' and 'eT3'. Regards. – Tchak Oct 12 '17 at 09:02
  • Note : I can use a non optimal solution writing the third line for every event 'xxxx' in my list of events though. – Tchak Oct 12 '17 at 09:07
  • Just remove the second EPL and use the following instead.....insert into MyEventWindow select * from MyEvent as arriving where not exists(select * from MyEventWindow as win where arriving.eventType=win.eventType); – user650839 Oct 12 '17 at 13:43
  • Perhaps you can simply use "MyEvent#time_accum(15 sec)#firstunique(eventType)" – user650839 Oct 12 '17 at 13:45
  • Hello, did you see my edit ? If you know the answer I can close this topic. Thanks ! – Tchak Oct 16 '17 at 12:37