4.0 KiB
4.0 KiB
| title | description | menu | weight | flux/v0/tags | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| tickscript.groupBy() function | `tickscript.groupBy()` groups results by the `_measurement` column and other specified columns. |
|
301 |
|
tickscript.groupBy() groups results by the _measurement column and other specified columns.
This function is comparable to Kapacitor QueryNode .groupBy.
Note: To group by time intervals, use window() or tickscript.selectWindow().
Function type signature
(<-tables: stream[A], columns: [string]) => stream[A] where A: Record
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
Parameters
columns
({{< req >}}) List of columns to group by.
tables
Input data. Default is piped-forward data (<-).
Examples
Group by host and region
import "contrib/bonitoo-io/tickscript"
data
|> tickscript.groupBy(columns: ["host", "region"])
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
Input data
| _time | _measurement | host | region | _field | _value |
|---|---|---|---|---|---|
| 2021-01-01T00:00:00Z | m | h1 | east | foo | 1.2 |
| 2021-01-01T00:01:00Z | m | h1 | east | foo | 3.4 |
| 2021-01-01T00:00:00Z | m | h2 | east | foo | 2.3 |
| 2021-01-01T00:01:00Z | m | h2 | east | foo | 5.6 |
| 2021-01-01T00:00:00Z | m | h3 | west | foo | 1.2 |
| 2021-01-01T00:01:00Z | m | h3 | west | foo | 3.4 |
| 2021-01-01T00:00:00Z | m | h4 | west | foo | 2.3 |
| 2021-01-01T00:01:00Z | m | h4 | west | foo | 5.6 |
Output data
| _time | *_measurement | *host | *region | _field | _value |
|---|---|---|---|---|---|
| 2021-01-01T00:00:00Z | m | h1 | east | foo | 1.2 |
| 2021-01-01T00:01:00Z | m | h1 | east | foo | 3.4 |
| _time | *_measurement | *host | *region | _field | _value |
|---|---|---|---|---|---|
| 2021-01-01T00:00:00Z | m | h2 | east | foo | 2.3 |
| 2021-01-01T00:01:00Z | m | h2 | east | foo | 5.6 |
| _time | *_measurement | *host | *region | _field | _value |
|---|---|---|---|---|---|
| 2021-01-01T00:00:00Z | m | h3 | west | foo | 1.2 |
| 2021-01-01T00:01:00Z | m | h3 | west | foo | 3.4 |
| _time | *_measurement | *host | *region | _field | _value |
|---|---|---|---|---|---|
| 2021-01-01T00:00:00Z | m | h4 | west | foo | 2.3 |
| 2021-01-01T00:01:00Z | m | h4 | west | foo | 5.6 |
{{% /expand %}} {{< /expand-wrapper >}}