content/flux/v0/stdlib/universe/window.md
window() groups records using regular time intervals.
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 row's _time value.
A single input row may be placed into zero or more output tables depending on
the parameters passed into window().
This function is intended to be used when timeColumn (_time by default) is not in the group key.
If timeColumn is in the group key, resulting output is confusing and generally not useful.
every, period, and offset parameters support all valid duration units,
including calendar months (1mo) and years (1y).
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.
(
<-tables: stream[A],
?createEmpty: bool,
?every: duration,
?location: {zone: string, offset: duration},
?offset: duration,
?period: duration,
?startColumn: string,
?stopColumn: string,
?timeColumn: string,
) => stream[B] where A: Record, B: Record
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
Duration of time between windows.
Duration of windows. Default is the every value.
period can be negative, indicating the start and stop boundaries are reversed.
Duration to shift the window boundaries by. Default is 0s.
offset can be negative, indicating that the offset goes backwards in time.
Location used to determine timezone. Default is the location option.
Column that contains time values. Default is _time.
Column to store the window start time in. Default is _start.
Column to store the window stop time in. Default is _stop.
Create empty tables for empty window. Default is false.
Input data. Default is piped-forward data (<-).
data
|> window(every: 30s)
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 4 | t1 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 1 | t2 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:30Z | 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:30Z | 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:30Z | 2021-01-01T00:00:20Z | 7 | t1 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:30Z | 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:30Z | 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:30Z | 2021-01-01T00:00:20Z | -3 | t2 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:30Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:30Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:30Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 4 | t1 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:30Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:30Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:30Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 1 | t2 |
{{% /expand %}} {{< /expand-wrapper >}}
data
|> window(every: 20s, period: 40s)
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 4 | t1 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 1 | t2 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:20Z | 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:20Z | 2021-01-01T00:00:10Z | 10 | t1 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:20Z | 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:20Z | 2021-01-01T00:00:10Z | 4 | t2 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:40Z | 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:40Z | 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:40Z | 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:40Z | 2021-01-01T00:00:30Z | 17 | t1 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:40Z | 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:40Z | 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:40Z | 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:00:40Z | 2021-01-01T00:00:30Z | 19 | t2 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:20Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:20Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:20Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:20Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 4 | t1 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:20Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:20Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:20Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:20Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 1 | t2 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:40Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:40Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 4 | t1 |
| *_start | *_stop | _time | _value | *tag |
|---|---|---|---|---|
| 2021-01-01T00:00:40Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:40Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 1 | t2 |
{{% /expand %}} {{< /expand-wrapper >}}
data
|> window(every: 1mo)
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| *_start | *_stop | _time | _value |
|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-04-01T00:00:00Z | 2021-01-01T00:00:00Z | 0 |
| 2021-01-01T00:00:00Z | 2021-04-01T00:00:00Z | 2021-01-16T00:00:00Z | 2 |
| 2021-01-01T00:00:00Z | 2021-04-01T00:00:00Z | 2021-01-31T00:00:00Z | 4 |
| 2021-01-01T00:00:00Z | 2021-04-01T00:00:00Z | 2021-02-15T00:00:00Z | 6 |
| 2021-01-01T00:00:00Z | 2021-04-01T00:00:00Z | 2021-03-02T00:00:00Z | 8 |
| 2021-01-01T00:00:00Z | 2021-04-01T00:00:00Z | 2021-03-17T00:00:00Z | 10 |
| *_start | *_stop | _time | _value |
|---|---|---|---|
| 2021-01-01T00:00:00Z | 2021-02-01T00:00:00Z | 2021-01-01T00:00:00Z | 0 |
| 2021-01-01T00:00:00Z | 2021-02-01T00:00:00Z | 2021-01-16T00:00:00Z | 2 |
| 2021-01-01T00:00:00Z | 2021-02-01T00:00:00Z | 2021-01-31T00:00:00Z | 4 |
| *_start | *_stop | _time | _value |
|---|---|---|---|
| 2021-02-01T00:00:00Z | 2021-03-01T00:00:00Z | 2021-02-15T00:00:00Z | 6 |
| *_start | *_stop | _time | _value |
|---|---|---|---|
| 2021-03-01T00:00:00Z | 2021-04-01T00:00:00Z | 2021-03-02T00:00:00Z | 8 |
| 2021-03-01T00:00:00Z | 2021-04-01T00:00:00Z | 2021-03-17T00:00:00Z | 10 |
{{% /expand %}} {{< /expand-wrapper >}}