CUMULATE

Syntax

Description of the illustration cumulate.gif

Purpose

The CUMULATE table function creates a set of expanding time windows. Each window starts at the same time, and its end boundary advances by a fixed step until it reaches the maximum window size.

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 CUMULATE.

step

The positive interval by which the end boundary advances. The value must be a non-null runtime constant of type INTERVAL DAY TO SECOND or INTERVAL YEAR TO MONTH.

size

The positive interval that specifies the maximum window size. The value must be an integer multiple of step.

offset

An optional interval that shifts the window alignment. If you omit offset, the windows use the Unix epoch as their origin. The value must be a non-null runtime constant.

Semantics

Datetime and Calendar Considerations

Examples

The following example creates cumulative windows that grow by five seconds and stop at 15 seconds:

SELECT ip, visit_time, window_start, window_end
FROM CUMULATE(
  visit,
  COLUMNS ( visit_time ),
  INTERVAL '5' SECOND,
  INTERVAL '15' SECOND
);

An event at 08:00:03 can appear in [08:00:00, 08:00:05), [08:00:00, 08:00:10), and [08:00:00, 08:00:15).

The following example counts rows in each cumulative window:

SELECT window_start, window_end, COUNT(*)
FROM CUMULATE(
  visit,
  COLUMNS ( visit_time ),
  INTERVAL '5' SECOND,
  INTERVAL '15' SECOND
)
GROUP BY window_start, window_end
ORDER BY window_start, window_end;

Restrictions

See Also: