# Time Window Functions

# tumble

A tumbling time window assigns records to non-overlapping, continuous windows with a fixed duration (interval).

tumble(time_attr, interval [, timezone])

Arguments

  • time_attr - Date and time. DateTime data type.
  • interval - Window interval in Interval data type.
  • timezone — Timezone name (optional).

Returned values

  • The inclusive lower and exclusive upper bound of the corresponding tumbling window.
  • Type: Tuple(DateTime, DateTime)

Example

SELECT tumble(now(), toIntervalDay('1'))
┌─tumble(now(), toIntervalDay('1'))─────────────┐
│ ('2023-10-27 00:00:00','2023-10-28 00:00:00') │
└───────────────────────────────────────────────┘

# hop

A hopping time window has a fixed duration (window_interval) and hops by a specified hop interval (hop_interval). If the hop_interval is smaller than the window_interval, hopping windows are overlapping. Thus, records can be assigned to multiple windows.

hop(time_attr, hop_interval, window_interval [, timezone])

Arguments

  • time_attr - Date and time. DateTime data type.
  • hop_interval - Hop interval in Interval data type. Should be a positive number.
  • window_interval - Window interval in Interval data type. Should be a positive number.
  • timezone — Timezone name (optional).

Returned values

  • The inclusive lower and exclusive upper bound of the corresponding hopping window. Since one record can be assigned to multiple hop windows, the function only returns the bound of the first window when hop function is used without WINDOW VIEW.
  • Type: Tuple(DateTime, DateTime)

Example

SELECT hop(now(), INTERVAL '1' SECOND, INTERVAL '2' SECOND)
┌─hop(now(), toIntervalSecond('1'), toIntervalSecond('2'))──┐
│ ('2023-10-27 15:10:17','2023-10-27 15:10:19')             │
└───────────────────────────────────────────────────────────┘

# tumbleStart

Returns the inclusive lower bound of the corresponding tumbling window.

tumbleStart(bounds_tuple);
tumbleStart(time_attr, interval [, timezone]);

# tumbleEnd

Returns the exclusive upper bound of the corresponding tumbling window.

tumbleEnd(bounds_tuple);
tumbleEnd(time_attr, interval [, timezone]);

# hopStart

Returns the inclusive lower bound of the corresponding hopping window.

hopStart(bounds_tuple);
hopStart(time_attr, hop_interval, window_interval [, timezone]);

# hopEnd

Returns the exclusive upper bound of the corresponding hopping window.

hopEnd(bounds_tuple);
hopEnd(time_attr, hop_interval, window_interval [, timezone]);
Last Updated: Tue Sep 10 2024 03:19:52 GMT+0000