keys() function
The keys()
function outputs the column keys in the group key of each input table.
For each input table, the function outputs a table with the same group key columns,
and a _value
column containing the labels of the input table’s group key.
Each row in an output table contains the group key value and the label of one column in the group key of the input table.
Each output table has the same number of rows as the size of the group key of the input table.
keys(column: "_value")
Parameters
column
Name of the output column in to store group key labels in. Default is “_value”`.
tables
Input data.
Default is piped-forward data (<-
).
Examples
The following examples use sample.data()
to simulate data queried from InfluxDB and illustrate how keys()
transforms data.
- Return group key columns for each input table
- Return all distinct group key columns in a single table
- Return group key columns as an array
Return group key columns for each input table
import "influxdata/influxdb/sample"
data = sample.data(set: "airSensor")
|> range(start: -30m)
|> filter(fn: (r) => r.sensor_id == "TLM0100")
data
|> keys()
Return all distinct group key columns in a single table
import "influxdata/influxdb/sample"
data = sample.data(set: "airSensor")
|> range(start: -30m)
|> filter(fn: (r) => r.sensor_id == "TLM0100")
data
|> keys()
|> keep(columns: ["_value"])
|> distinct()
Return group key columns as an array
To return group key columns as an array:
- Use
keys()
to replace the_value
column with the group key labels. - Use
findColumn()
to return the_value
column as an array.
import "influxdata/influxdb/sample"
data = sample.data(set: "airSensor")
|> range(start: -30m)
|> filter(fn: (r) => r.sensor_id == "TLM0100")
data
|> keys()
|> findColumn(fn: (key) => true, column: "_value")
// Returns [_start, _stop, _field, _measurement, sensor_id]
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, the following resources are available:
InfluxDB Cloud customers can contact InfluxData Support.