Skip to main content

Bound data in batches by event count

Alternatively, you can aggregate data in batches of n number of events. For example:

CREATE JUMPING WINDOW ProductData_100
OVER RetailOrders
KEEP 100 ROWS
PARTITION BY storeId;

CREATE CQ GetProductActivity
INSERT INTO ProductTrackingStream
SELECT pd.storeId, COUNT(*), SUM(pd.orderAmount), FIRST(pd.dateTime)
FROM ProductData_100 pd;

The output stream receives an event for each batch of 100 events from each store. You might use code like this to trigger a potential fraud alert when a store's order count or amount is anomalously high. (PARTITION BY storeId means the window will contain the data for the most recent 100 orders for each store. Without this clause, the window would contain 100 events total for all stores.)