Select events with a maximum in a sliding window

119 views Asked by At

I have this stream :

define stream locationStream (cell string, device string, power long);

I want to select in this stream, with a sliding windows of 10 seconds, for every device, the value of the 'cell' attribute for which 'power' is the largest.

What queries should I use to get this result with Siddhi ? Something like

from locationStream#window.time(10 seconds)
select max(power), device, <cell where power = max(power)>
group by device
insert all events into cellStream
1

There are 1 answers

0
Tishan On BEST ANSWER

You can use Siddhi maxByTimeWindow offered through extrema extension. Usage is documented in shared resources. You will have to use this with a partition to get per device max. Suggested query should look like below.

partition with ( device of locationStream )
begin
  from locationStream#extrema:maxByTime(power, 10 sec)
  select power, device, cell
  insert events into cellStream
end;