Back to Influxdb

tickscript.groupBy() function

content/flux/v0/stdlib/contrib/bonitoo-io/tickscript/groupby.md

latest3.7 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/contrib/bonitoo-io/tickscript/tickscript.flux#L431-L435 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

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
js
(<-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

js
import "contrib/bonitoo-io/tickscript"

data
    |> tickscript.groupBy(columns: ["host", "region"])

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time_measurementhostregion_field_value
2021-01-01T00:00:00Zmh1eastfoo1.2
2021-01-01T00:01:00Zmh1eastfoo3.4
2021-01-01T00:00:00Zmh2eastfoo2.3
2021-01-01T00:01:00Zmh2eastfoo5.6
2021-01-01T00:00:00Zmh3westfoo1.2
2021-01-01T00:01:00Zmh3westfoo3.4
2021-01-01T00:00:00Zmh4westfoo2.3
2021-01-01T00:01:00Zmh4westfoo5.6

Output data

_time*_measurement*host*region_field_value
2021-01-01T00:00:00Zmh1eastfoo1.2
2021-01-01T00:01:00Zmh1eastfoo3.4
_time*_measurement*host*region_field_value
2021-01-01T00:00:00Zmh2eastfoo2.3
2021-01-01T00:01:00Zmh2eastfoo5.6
_time*_measurement*host*region_field_value
2021-01-01T00:00:00Zmh3westfoo1.2
2021-01-01T00:01:00Zmh3westfoo3.4
_time*_measurement*host*region_field_value
2021-01-01T00:00:00Zmh4westfoo2.3
2021-01-01T00:01:00Zmh4westfoo5.6

{{% /expand %}} {{< /expand-wrapper >}}