Syntax for defining timeInterval windows
- Wname
- Specifies the ID of the operator port connected to the window.
- timeInterval
- Specifies that the window-kind tuples are placed into panes which correspond to equal intervals in the event-time domain. A pane includes tuples with an event time greater or equal to the start time of the pane and lower than the end time.
- intervalDuration(value)
- Specifies the required duration between the lower and upper interval endpoints. It must be greater than zero (0.0).
- creationPeriod(value)
- Specifies the duration between adjacent intervals. The default value is equal to intervalDuration. It must be greater than zero (0.0).
- discardAge(value)
- Defines the duration between the point in time when a window pane becomes complete and the point
in time when the window does not accept late tuples any longer. It must be greater or equal to zero
(0.0). The default value is zero (0.0).Note: Tuples which arrive later (with respect to the current watermark) than the discarding age value are ignored. Closed panes are deleted.
- intervalOffset(value)
- Defines a point-in-time value which coincides with an interval start time. Panes partition the
event time domain into intervals of the form:
where 0.0 is the Unix Epoch:[N * creationPeriod + intervalOffset, N * creationPeriod + intervalDuration + intervalOffset)
1970-01-01T00:00:00Z UTC
.The value must be in the interval
[0.0, intervalDuration)
.
The value
parameters above represent seconds, regardless of the type and the
resolution of the event-time attribute.
Leap seconds
window W: timeInterval, intervalDuration(3600.0), creationPeriod(1200.0)
00:00:00
to 01:00:00
,
00:20:00
to 01:20:00
, 00:40:00
to
01:40:00
, and so on. The first window after a leap_second occurs might have a duration of 3601
seconds, although the
subtraction of intervalEnd()
minus intervalStart()
is still 3600
because of the Unix time second adjustment. Default trigger policy
When the current event time, which is specified by the watermark, becomes greater than or equal to the interval's end, the window pane becomes complete and triggers. If tuples with event times within the pane’s interval arrive after the pane has triggered (late tuples), the pane triggers again and the operator which handles the trigger event re-calculates output taking into account the late data. This means that a window pane which has received late data (late tuples) triggers again when the operator's watermark is updated.
When a pane triggers, the event handler calculates aggregate values based on the pane content.
Example of a traffic flow
The following example defines the maximum traffic flow over each freeway using event-time intervals of 50 seconds which slide every 25 seconds.
// Get maximum traffic flow over each freeway, over event-time intervals of
// size 50 seconds which slide every 25 seconds.
stream<TrafficInfo> MaxFlow = Aggregate(Traffic) {
window PreWork : timeInterval, intervalDuration(50.0), intervalOffset(0.0),
discardAge(1000.0), creationPeriod(25.0), partitioned;
param partitionBy : freeway;
output MaxFlow :
timeStart = intervalStart(),
timeEnd = intervalEnd(),
freeway = ArgMax(laneFlow, freeway),
eventtime = ArgMax(laneFlow, eventtime),
laneFlow = Max(laneFlow);
}
Example of an adjacent time intervals of the duration of one hour
[00:20 .. 01:20)
, [01:20 .. 02:20)
, and
so on. 00:30
in time zones with fractional hour offset
such as India (+5:30)
.window W: timeInterval intervalDuration(3600.0), intervalOffset(1200.0)
Example of intervals of the duration of one hour
[00:00 .. 01:00)
, [00:20 ..
01:20)
, and so on. 00:30
in time zones with
fractional hour offset such as Iran (+3:30)
or Venezuela
(-4:30)
.window W: timeInterval intervalDuration(hours(1)), creationPeriod(minutes(20), discardAge(hours(6))
- The parameter values are expressed using functions defined in the
com.teracloud.streamsx.datetime
toolkit. - The discard age is six hours. If a tuple with time
00:00
arrives at the window before watermark07:00
, the tuple is inserted into interval[00:00 .. 01:00)
and others, and processed as a late tuple. The tuple is discarded if it arrives after watermark07:00
.