Skip to main content
Version: 0.8

Define Time Window

Time window is an important attribute of your continuous aggregation query. It defines how the data is aggregated in the flow. These time windows are left-closed and right-open intervals.

A time window corresponds to a range of time. Data from source table will be mapped to the corresponding window based on the time index column. Time window is also the scope of one calculation of an aggregation expression, so each time window will result in one row in the result table.

GreptimeDB provides two types of time windows: hop and tumble, or "sliding window" and "fixed window" in other words. You can specify the time window in the GROUP BY clause using hop() function or tumble() function respectively. These two functions are only supported in continuous aggregate queries's GROUP BY position.

Here illustrates how the hop() and tumble() functions work:

Time Window

Tumble

tumble() defines fixed windows that do not overlap.

tumble(col, interval, start_time)
  • col specifies use which column to compute the time window. The provided column must have a timestamp type.
  • interval specifies the size of the window. The tumble function divides the time column into fixed-size windows and aggregates the data in each window.
  • start_time specify the start time of the first window.

Hop (not supported yet)

hop defines sliding window that moves forward by a fixed interval. This feeaure is not supported yet and is expected to be available in the near future.