Updated on 2025-09-05 GMT+08:00

Window

Function

A TUMBLE window (rolling window) is the most basic window type in Flink. It groups an unbounded data stream into continuous non-overlapping time windows with fixed size. Each data element belongs to only one specific window.

  • An unbounded data flow is a data set that has data generated continuously. Theoretically, it has no end point, and data elements arrive in a time sequence. In SecMaster, streaming tables are unbounded data streams, for example, tables starting with s_.
  • Data elements are independent records in an unbounded data stream.
Figure 1 Window example

Syntax Format

SELECT {[window_start], [window_end], agg_function(column) | *}
FROM TABLE(
    TUMBLE(TABLE table_name, DESCRIPTOR(time_column), interval)
)
[GROUP BY window_start, window_end, columns]

Syntax Description

  • agg_function: indicates an aggregation function, such as SUM, AVG, and COUNT.
  • table_name: indicates a table, which is the data source for time-based grouping.
  • time_column: indicates the time attribute column used to group records into windows. It must be either event time or processing time.
  • interval: indicates the window size, for example, INTERVAL '5' SECOND and INTERVAL '10' MINUTE.
  • window_start and window_end: indicate the start time and end time of the window generated by the system.

Precautions

  • If the window statement is used in a stream model, it will be a delay for the model to generate pop-up alerts. The delay time depends on the window size.
  • If the stream table data is delayed or the stream is interrupted, the result data of the last window in the stream model is delayed until the data does not meet the time condition of the window. In this case, a new window is generated. After the old window is closed, an alert is generated.
  • You cannot create a window for a stream table directly. You need to use the WITH statement to create a temporary view and then create a window for the temporary view.

Example of the TUMBLE WINDOW Statement

  • Example statement 1

    Use the tumble window function to create a window for the product data. The window size is 10 minutes.

    WITH a_view as (SELECT * FROM bid)
    SELECT * FROM TABLE(
    TUMBLE(TABLE a_view, DESCRIPTOR(bidtime), INTERVAL '10' MINUTES));
  • Example statement 2

    Query the total price of all items in the bid table every 10 minutes.

    WITH b_view as (SELECT * FROM bid)
    SELECT window_start, window_end, SUM(price) as price
    FROM TABLE(
    TUMBLE(TABLE b_view, DESCRIPTOR(bidtime), INTERVAL '10' MINUTES))
    GROUP BY window_start, window_end