Session
Provides examples on aggregating events over continuous activity sessions in a sliding manner.
To aggregate events in batches, or based on events, refer other the examples in Data Summarization section. For more information on windows refer the Siddhi query guide.
define stream PurchaseStream
(userId string, item string, price double);
@info(name = 'Session-analysis')
from PurchaseStream#window.session(1 min, userId)
select userId,
count() as totalItems,
sum(price) as totalPrice
group by userId
insert into UserIdPurchaseStream;
@info(name = 'Session-analysis-with-late-event-arrivals')
from PurchaseStream#window.session(1 min, userId, 20 sec)
select userId,
count() as totalItems,
sum(price) as totalPrice
group by userId
insert into OutOfOrderUserIdPurchaseStream;
|
|
|
|
|
Aggregate events over a |
|
Calculate count and sum of |
|
Output when events are added to the session. |
|
|
|
Aggregate events over a |
|
Calculate count and sum of |
|
Output when events are added to the session. |
Aggregation Behavior
When events are sent to PurchaseStream
stream, following events will get emitted at UserIdPurchaseStream
stream via Session-analysis
query,
and OutOfOrderUserIdPurchaseStream
stream via Session-analysis-with-late-event-arrivals
query.
Time | Event Timestamp | Input to PurchaseStream |
Output at UserIdPurchaseStream |
Output at OutOfOrderUserIdPurchaseStream |
---|---|---|---|---|
9:00:00 | 9:00:00 | ['1001' , 'cake' , 18.0 ] |
['1001' , 1 , 18.0 ] |
['1001' , 1 , 18.0 ] |
9:00:20 | 9:00:20 | ['1002' , 'croissant' , 23.0 ] |
['1002' , 1 , 23.0 ] |
['1002' , 1 , 23.0 ] |
9:00:40 | 9:00:40 | ['1002' , 'cake' , 22.0 ] |
['1002' , 2 , 45.0 ] |
['1002' , 2 , 45.0 ] |
9:01:05 | 9:00:50 | ['1001' , 'pie' , 22.0 ] |
No events, as event arrived late, and did not fall into a session. | ['1001' , 2 , 40.0 ] |
9:01:10 | 9:01:10 | ['1001' , 'cake' , 10.0 ] |
['1001' , 1 , 10.0 ] |
['1001' , 3 , 50.0 ] |
9:01:50 | 9:01:50 | ['1002' , 'cake' , 20.0 ] |
['1002' , 1 , 20.0 ] |
['1002' , 1 , 23.0 ] |
9:02:40 | 9:02:40 | ['1001' , 'croissant' , 23.0 ] |
['1001' , 1 , 23.0 ] |
['1001' , 1 , 23.0 ] |