With Esper how to start a window for X minutes from first event timestamp?

52 Views Asked by At

I am trying to start a window and to make it lives for X minutes.

Select a,b
from Event.win:time(120) -> this gives me a sliding window
match_recognize(
partition by sensor
...
)

I tried also

Select a,b
from Event.win:ext_timed(time.time, 120) -> this gives me a sliding window as well
match_recognize(
partition by sensor
...
)

Is there a way to start a window for 120sec from the first coming event and to end it even new events are coming?

Thanks for your help

2

There are 2 best solutions below

0
user3613754 On BEST ANSWER

If you want a start processing events when a certain event/time occurred and stop processing after X minutes then that is done with contexts.

create context FromNowForXSeconds start @now end after X seconds;
context FromNowForXSeconds select ... from ....;
0
Dakotah North On

With match recognize you can set up partitioned windows with interval.

With the optional interval keyword and time period you can control how long the runtime should wait for further events to arrive that may be part of a matching event sequence, before indicating a match.

For example, from EPL reference chapter 8.8 ... the interval timer below starts at the arrival of the first event matching a sequence for a partition.

TemperatureSensorEvent
match_recognize (
partition by device
measures A.id as a_id, count(B.id) as count_b, first(B.id) as first_b, last(B.id)
 as last_b
pattern (A B*)
interval 5 seconds
define 
 A as A.temp > 100,
 B as B.temp > 100)