Skip to main content

Bounding by both time and event count

When appropriate, you may bound a window by both time and event count. For example:

CREATE WINDOW StoreTimeoutWindow
OVER RetailOrders
KEEP 1 ROWS WITHIN 5 MINUTE 
PARTITION BY storeId;

CREATE TYPE StoreNameData(
  storeId String KEY,
  storeName String
);
CREATE CACHE StoreNameLookup using FileReader (
  directory: 'stores',
  wildcard: 'StoreNames.csv'
)
PARSE USING DSVParser(
  header: Yes
) QUERY(keytomap:'storeId') OF StoreNameData;

CREATE StoreTimeoutCheck
INSERT INTO StoreTimeoutStream
SELECT c.storeId
FROM StoreTimeoutWindow w
LEFT OUTER JOIN StoreNameData c
ON w.storeId = c.storeId
WHERE w.storeId IS NULL
GROUP BY c.storeId;

This five-minute sliding window contains the most recent order event (KEEP 1 ROWS) for each store. The output from the CQ could be used to generate an alert whenever five minutes have passed without a new order (indicating that the store is probably offline).