On a high level we can do something like this:
We would need a Siddhi table, where we store a pivot timestamp. We can route events to streams based on this pivot timestamp. Let's call this table: TimeStampTable(pivotTimestamp long)
.
At each event of IncomingStream(eventTimestamp long, ..otherAttributes..)
, we do a join with TimeStampTable
, and check if an entry exists at TimeStampTable
.
- A. If an entry doesn't exist, insert
eventTimestamp
to TimeStampTable
. This is going to function as the pivot timestamp. Get 0
as timeDiff
.
- B. If exists, get
eventTimestamp - pivotTimestamp
as timeDiff
.
Based on timeDiff
, put a label to each event (basically add a string attribute and pass it to the next stream). I.e, WITHIN_FIRST_MINUTE
, and WITHIN_THREE_HOURS
.
Route events to appropriate streams based on the above label.
At step (2.B), if timeDiff >= 3 hours
, replace pivotTimestamp
with the current timestamp.