Aggregate Sliding
Description
This page describes the behavior specific to aggregations in the sliding window. For concepts and configuration common to all time-window aggregations, see Aggregations in time windows.
A sliding window calculates aggregate values over the most recent period of time. For example, a one-hour sliding window contains events from the most recent hour.
Whenever a new event arrives, the window moves forward to include that event, and the incoming event is enriched with aggregate values calculated over the current window.
By default, an updated aggregate is produced only when a new event enters the window. If emitWhenEventLeft is true, Nussknacker produces an additional aggregate event when an older event leaves the window. This makes changes caused by both entering and leaving events observable downstream. As this is a new event, variables belonging to the original events, such as #input and #inputMeta, are therefore unavailable downstream.

For simplicity, all events share the same groupBy value (= "purple")

For simplicity, all events share the same groupBy value (= "purple")
Let's use the following example in case the above explanation is not clear. Imagine you are counting Porsches passing a point on a motorway using a one-hour sliding window, with a separate count for each color. To keep the example simple, consider only red Porsches. Suppose two pass the observation point: one at 9:25 and another at 9:45.
The following table shows aggregates emitted by the sliding-window in each configuration option.
| Time | What happened | Count (emitWhenEventLeft is false) | Count (emitWhenEventLeft is true) |
|---|---|---|---|
| 9.25am | First red Porsche enters | 1 | 1 |
| 9.45am | Second red Porsche enters | 2 | 2 |
| 10.25am | First Porsche leaves the 1h window | N/A | 1 |
| 10.45am | Second Porsche leaves the 1h window | N/A | 0 |
Parameters and configuration
Parameters common to all windows are described here.
| Name | Description |
|---|---|
windowLength | Window `length |
emitWhenEventLeft | If true, an additional aggregate event is emitted when an event leaves the window. Default: false. |