aggregateWindow() function
*Function type: Aggregate*
As data is windowed into separate tables and processed, the _time
column is dropped from each group key. This function copies the timestamp from a remaining column into the _time
column. View the function definition.
aggregateWindow()
restores the original _start
and _stop
values of input data and, by default, uses _stop
to set the _time
value for each aggregated window. Each row in the output of aggregateWindow
represents an aggregated window ending at _time
.
Make sure fn
parameter names match each specified parameter. To learn why, see .
The duration of windows.
Calendar months and years
every
supports all , including calendar months (1mo
) and years ().
fn
The used in the operation.
*Data type: Function*
Only aggregate and selector functions with a column
parameter (singular) work with aggregateWindow()
.
The column on which to operate. Defaults to "_value"
.
*Data type: String*
timeSrc
The time column from which time is copied for the aggregate record. Defaults to "_stop"
.
The “time destination” column to which time is copied for the aggregate record. Defaults to "_time"
.
*Data type: String*
createEmpty
For windows without data, this will create an empty window and fill it with a null
aggregate value. Defaults to true
.
*Data type: Boolean*
The examples below use a data
variable to represent a filtered data set.
data = from(bucket: "example-bucket")
|> range(start: -1h)
|> filter(fn: (r) =>
r._measurement == "mem" and
r._field == "used_percent")
Use an aggregate function with default parameters
The following example uses the default parameters of the to aggregate time-based windows:
Specify parameters of the aggregate function
data
|> aggregateWindow(
every: 5m,
fn: (column, tables=<-) => tables |> quantile(q: 0.99, column:column)
)
Window and aggregate by calendar month
aggregateWindow = (every, fn, column="_value", timeSrc="_stop", timeDst="_time", tables=<-) =>
tables
|> window(every:every)
|> fn(column:column)
|> window(every:inf, timeColumn:timeDst)