Documentation

window() function

Flux 0.7.0+

The window() function groups records based on a time value. The function calculates time windows and stores window bounds in the _start and _stop columns. _start and _stop values are assigned to rows based on the _time value.

A single input row may be placed into zero or more output tables depending on the parameters passed into the window() function.

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

Parameters

Calendar months and years

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

Window by week

When windowing by week (1w), weeks are determined using the Unix epoch (1970-01-01T00:00:00Z UTC). The Unix epoch was on a Thursday, so all calculated weeks begin on Thursday.

every

Duration of time between windows. Defaults to period value.

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.

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.

timeColumn

The column containing time. Defaults to "_time".

startColumn

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

stopColumn

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

createEmpty

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

tables

Input data. Default is piped-forward data (<-).

Examples

The following examples use data provided by the sampledata package to show how window() transforms data.

Window data into 30 second intervals

import "sampledata"

data = sampledata.int()
  |> range(start: sampledata.start, stop: sampledata.stop)
 
data 
  |> window(every: 30s)

View input and output

Window every 20 seconds covering 40 second periods

import "sampledata"

data = sampledata.int()
  |> range(start: sampledata.start, stop: sampledata.stop)
 
data 
  |> window(every: 20s, period: 40s)

View input and output

Window by calendar month

The following example uses generate.from to illustrate windowing by calendar month.

import "generate"

timeRange = {start: 2021-01-01T00:00:00Z, stop: 2021-04-01T00:00:00Z}

data = generate.from(
    count: 6,
    fn: (n) => n + n,
    start: timeRange.start,
    stop: timeRange.stop
  )
  |> range(start: timeRange.start, stop: timeRange.stop)

data
  |> window(every: 1mo)

View input and output


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.