group() function
The group()
function groups records based on their values for specific columns.
It produces tables with new group keys based on provided properties.
Specify an empty array of columns to ungroup data or merge all input tables into a single output table.
group(columns: ["host", "_measurement"], mode:"by")
// OR
group(columns: ["_time"], mode:"except")
// OR
group()
For more information about Flux table grouping, see Data model - Restructure tables.
Group does not guarantee sort order
group()
does not guarantee the sort order of output records.
To ensure data is sorted correctly, use sort()
after group()
.
data
|> group()
|> sort(columns: ["_time"])
Parameters
columns
List of columns to use in the grouping operation.
Defaults to []
.
mode
The mode used to group columns. Default is "by"
.
The following modes are available:
by
: Groups records by columns defined in thecolumns
parameter.except
: Groups records by all columns except those defined in thecolumns
parameter.
tables
Input data.
Default is piped-forward data (<-
).
Examples
The following examples use data provided by the sampledata
package
to show how group()
transforms data.
Group by specific columns
import "sampledata"
sampledata.int()
|> group(columns: ["_time", "tag"])
Group by everything except time
import "sampledata"
sampledata.int()
|> group(columns: ["_time"], mode: "except")
Ungroup data
import "sampledata"
// Merge all tables into a single table
sampledata.int()
|> group()
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for Flux and this documentation. To find support, use the following resources:
InfluxDB Cloud customers can contact InfluxData Support.