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.

Function type: Transformation
Output data type: Object

window(
  every: 5m,
  period: 5m,
  offset: 12h,
  timeColumn: "_time",
  startColumn: "_start",
  stopColumn: "_stop"
)

// OR

window(
  intervals: intervals(every: 5m, period: 5m, offset: 12h),
  timeColumn: "_time",
  startColumn: "_start",
  stopColumn: "_stop"
)

Parameters

every,period or intervals is required.

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

The offset duration relative to the location offset. It can be negative, indicating that the offset goes backwards in time. The default aligns the window boundaries with now.

Data type: Duration

intervals

A function that returns an interval generator, a set of intervals used as windows.

Data type: Function

Example interval generator function
intervals(every:1d, period:8h, offset:9h)

When intervals is used, every, period, and offset cannot be used or need to be set to 0.

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

Examples

Window data into 10 minute intervals

from(bucket:"telegraf/autogen")
  |> range(start:-12h)
  |> window(every:10m)
  // ...

Window data using intervals function

The following windows data into 8 hour intervals starting at 9AM every day.

from(bucket:"telegraf/autogen")
  |> range(start:-12h)
  |> window(intervals: intervals(every:1d, period:8h, offset:9h))

GROUP BY time()

This documentation is open source. See a typo? Please, open an issue.


Need help getting up and running? Get Support