Batch (Tumbling) Event Count
Provides examples on aggregating events based on event count in a batch (tumbling) manner.
To aggregate events in a sliding manner, based on time, or by session, refer other the examples in Data Summarization section. For more information on windows refer the Siddhi query guide.
define stream TemperatureStream
(sensorId string, temperature double);
@info(name = 'Overall-analysis')
from TemperatureStream#window.lengthBatch(4)
select avg(temperature) as avgTemperature,
max(temperature) as maxTemperature,
count() as numberOfEvents
insert into OverallTemperatureStream;
@info(name = 'SensorId-analysis')
from TemperatureStream#window.lengthBatch(5)
select sensorId,
avg(temperature) as avgTemperature,
min(temperature) as maxTemperature
group by sensorId
having avgTemperature >= 20.0
insert into SensorIdTemperatureStream;
|
|
|
|
|
Aggregate every |
|
Calculate average, maximum, and count for |
|
|
|
Aggregate every |
|
|
|
Calculate average, and minimum for |
|
Output events only when |
|
Aggregation Behavior
When events are sent to TemperatureStream
stream, following events will get emitted at OverallTemperatureStream
stream via Overall-analysis
query,
and SensorIdTemperatureStream
stream via SensorId-analysis
query.
Input to TemperatureStream |
Output at OverallTemperatureStream |
Output at SensorIdTemperatureStream |
---|---|---|
['1001' , 19.0 ] |
- | - |
['1002' , 26.0 ] |
- | - |
['1002' , 24.0 ] |
- | - |
['1001' , 20.0 ] |
[22.5 , 26.0 , 4 ] |
- |
['1001' , 21.0 ] |
- | ['1002' , 25.5 , 24.0 ], [ '1001' , 20.0 , 19.0 ] |
['1002' , 22.0 ] |
- | - |
['1001' , 21.0 ] |
- | - |
['1002' , 22.0 ] |
[21.5 , 22.0 , 4 ] |
- |