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.

*Function type: Transformation*

  1. group(columns: ["host", "_measurement"], mode:"by")
  2. // OR
  3. group(columns: ["_time"], mode:"except")
  4. // OR
  5. group()

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().

  1. data
  2. |> group()
  3. |> sort(columns: ["_time"])

Parameters

columns

List of columns to use in the grouping operation. Defaults to [].

*Data type: Array of strings*

mode

The mode used to group columns.

*Data type: String*

The following options are available:

  • by
  • except

Defaults to "by".

by

Groups records by columns defined in the columns parameter.

except

Groups records by all columns except those defined in the columns parameter.

Examples

Group by host and measurement
  1. from(bucket: "example-bucket")
  2. |> range(start: -30m)
  3. |> group(columns: ["host", "_measurement"])
Group by everything except time
  1. from(bucket: "example-bucket")
  2. |> range(start: -30m)
  3. |> group(columns: ["_time"], mode: "except")
Ungroup data
  1. // Merge all tables into a single table
  2. from(bucket: "example-bucket")
  3. |> range(start: -30m)
  4. |> group()

Related articles