Skip to main content
Version: Current

Window Top-N

Mode: Streaming

Description​

The Window Top-N node (window-top-n) splits the stream into fixed (tumbling) windows of event time and emits, for every window and every key, the N records with the highest (or lowest) value of a chosen field - e.g. the three largest transactions of every customer in every hour.

Under the hood the node runs a Flink SQL window Top-N query over the incoming records.

  • The input of the node is one record variable available before the node (by default #input) - all its fields, or a selected subset, become the fields of the output, plus record_time, window_start and window_end.
  • The node clears all upstream variables - after the node only the output variable is available.

The node is available only in the Streaming processing mode, for unbounded streams.

The Window Top-N node window: input variable, partition key, ranking field and direction, N, window size and output variable

Parameters and configuration​

NameDescription
InputThe record variable and the fields to keep in the output.
Partition byThe fields making up the key; the ranking is computed separately for every combination of their values. With no fields, one ranking per window.
Order byThe field the records are ranked by, and the direction: DESC keeps the highest values, ASC the lowest.
NHow many records per window and key to keep, at least 1.
Window sizeThe length of the window, e.g. 1 HOUR.
Output variable nameThe name of the variable holding a kept record.

Additional considerations​

  • The node is stateful: open windows live in Flink state and are restored from a savepoint when the scenario is redeployed. Changing the key, the order or the window size may make the state incompatible.
  • Records are emitted when the window closes, not when they arrive. Late records (behind the watermark) are dropped. Records with equal values of the order field are ranked in an unspecified order.
  • The node can't be mocked in scenario tests - it has to be fed real records.