window() function

The window() function groups records based on a time value. New columns are added to uniquely identify each window. Those columns are added to the group key of the output tables.

A single input record will be placed into zero or more output tables, depending on the specific windowing function.

By default the start boundary of a window will align with the Unix epoch (zero time) modified by the offset of the location option.

*Function type: Transformation
**
Output data type:* Record

  1. window(
  2. every: 5m,
  3. period: 5m,
  4. offset: 12h,
  5. timeColumn: "_time",
  6. startColumn: "_start",
  7. stopColumn: "_stop",
  8. createEmpty: false
  9. )

Parameters

Calendar months and years

every, period, and offset support all valid duration units, including calendar months (1mo) and years (1y).

every

Duration of time between windows. Defaults to period value.

*Data type: Duration*

period

Duration of the window. Period is the length of each interval. It can be negative, indicating the start and stop boundaries are reversed. Defaults to every value.

*Data type: Duration*

offset

Offset is the duration by which to shift the window boundaries. It can be negative, indicating that the offset goes backwards in time. Defaults to 0, which will align window end boundaries with the every duration.

*Data type: Duration*

timeColumn

The column containing time. Defaults to "_time".

*Data type: String*

startColumn

The column containing the window start time. Defaults to "_start".

*Data type: String*

stopColumn

The column containing the window stop time. Defaults to "_stop".

*Data type: String*

createEmpty

Specifies whether empty tables should be created. Defaults to false.

*Data type: Boolean*

Examples

Window data into 10 minute intervals

  1. from(bucket:"example-bucket")
  2. |> range(start: -12h)
  3. |> window(every: 10m)
  4. // ...

Window by calendar month

  1. from(bucket:"example-bucket")
  2. |> range(start: -1y)
  3. |> window(every: 1mo)
  4. // ...

Related articles