Jérémie B
Jérémie B

Reputation: 11032

Select events with a maximum in a sliding window

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

Upvotes: 0

Views: 110

Answers (1)

Tishan
Tishan

Reputation: 890

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;

Upvotes: 1

Related Questions