TUMBLE

Syntax

Description of the illustration tumble.gif

Purpose

The TUMBLE table function assigns rows to consecutive, non-overlapping time windows of a fixed size. Each row is assigned to the window that contains the value in the specified datetime column.

Arguments

schema

The schema that contains the input table or view. If you omit schema, then the database uses the schema of the current user.

table | view

The input table or view. The function returns all columns from this row source and adds WINDOW_START and WINDOW_END columns.

query_name

The name of a query block in a WITH clause.

COLUMNS (datetime_column)

Specify exactly one datetime column. The column can have any of these data types:

You cannot specify an expression. The function does not implicitly convert a character value to a datetime value. Convert the value before you pass the table or view to TUMBLE.

size

The positive interval that specifies the duration of each window. The value must be a non-null runtime constant of type INTERVAL DAY TO SECOND or INTERVAL YEAR TO MONTH.

offset

An optional positive or negative interval that shifts the window alignment. If you omit offset, the windows use the Unix epoch, January 1, 1970 00:00 UTC, as their origin. The value must be a non-null runtime constant.

Semantics

Datetime and Calendar Considerations

Examples

The following example assigns each visit to a 10-second window based on its visit time:

SELECT ip, visit_time, window_start, window_end
FROM TUMBLE(
  visit,
  COLUMNS ( visit_time ),
  INTERVAL '10' SECOND
)
ORDER BY visit_time;

The following example shifts the window alignment by 5 seconds. The window size remains 10 seconds; the offset changes where the windows begin and end:

SELECT ip, visit_time, window_start, window_end
FROM TUMBLE(
  visit,
  COLUMNS ( visit_time ),
  INTERVAL '10' SECOND,
  INTERVAL '5' SECOND
)
ORDER BY visit_time;

The following example returns the number of visits in each window:

SELECT window_start, window_end, COUNT(*)
FROM TUMBLE(
  visit,
  COLUMNS ( visit_time ),
  INTERVAL '10' SECOND
)
GROUP BY window_start, window_end
ORDER BY window_start, window_end;

Restrictions

See Also: