Esper - Delayed output of every event in a batch

59 Views Asked by At

In esper, I have a stream which is getting input every X minutes, so essentially a batch of events at the same time every X minutes.

I also have an application built on top of esper, which requires in this case (details of that are not relevant) that every output event in the batch is delayed by X seconds. What i specifically mean by this is if for example 500 events are coming in every 10 minutes, i want to go through the 500 events and every lets say 2 seconds, i want to get esper output a single event from the batch. (Even the order does not really matter).

So i would need to help writing a query which can achieve this.

I have been playing around with time windows and with the output clause but so far the closest i got is every event in the batch got output every 2 seconds. (Which is not what i want) I achieved this with the following query: select * from SomeType.std:unique(someId) output snapshot every 2 sec

List of events used for simulating the problem on esper online tool (3 events batch):

SomeType={someId='1', delay=2}
SomeType={someId='2', delay=3}
SomeType={someId='3', delay=4}

Result in esper online:

At: 2001-01-01 08:00:02.000
Statement: out
Insert
SomeType={someId='1', delay=2}
SomeType={someId='2', delay=3}
SomeType={someId='3', delay=4}
At: 2001-01-01 08:00:04.000
Statement: out
Insert
SomeType={someId='1', delay=2}
SomeType={someId='2', delay=3}
SomeType={someId='3', delay=4}

... and so on

Desired result:

At: 2001-01-01 08:00:02.000
Statement: out
Insert
SomeType={someId='1', delay=2}
At: 2001-01-01 08:00:04.000
Statement: out
Insert
SomeType={someId='2', delay=3}
At: 2001-01-01 08:00:06.000
Statement: out
Insert
SomeType={someId='3', delay=4}

... and so on. So every event separately delayed and output.

1

There are 1 best solutions below

0
user3613754 On

It is a bit unclear to me why the incoming events have a "delay" field and value {2,3,4} but the output is 08:00:02 and 08:00:04 and 08:00:06. Should the input have "t=t.plus(2)" to advance time by 2 seconds between events and is "delay" relevant and if yes, how?

Not knowing the answer to above, I can still suggest you use the remove stream of a 2-second time window, like so:

select rstream * from SomeType#time(2)