| title |
description |
menu |
weight |
flux/v0/tags |
introduced |
| keys() function |
`keys()` returns the columns that are in the group key of each input table.
|
| flux_v0_ref |
| name |
parent |
identifier |
| keys |
universe |
universe/keys |
|
|
101 |
|
0.13.0 |
keys() returns the columns that are in the group key of each input table.
Each output table contains a row for each group key column label.
A single group key column label is stored in the specified column for each row.
All columns not in the group key are dropped.
Function type signature
(<-tables: stream[A], ?column: string) => stream[B] where A: Record, B: Record
{{% caption %}}
For more information, see Function type signatures.
{{% /caption %}}
Parameters
column
Column to store group key labels in. Default is _value.
tables
Input data. Default is piped-forward data (<-).
Examples
Return group key columns for each input table
data
|> keys()
{{< expand-wrapper >}}
{{% expand "View example input and output" %}}
Input data
| *_field |
*_measurement |
*sensorID |
_time |
_value |
| co |
airSensors |
TLM0100 |
2021-09-08T14:21:57Z |
0.31 |
| co |
airSensors |
TLM0100 |
2021-09-08T14:22:07Z |
0.295 |
| co |
airSensors |
TLM0100 |
2021-09-08T14:22:17Z |
0.314 |
| co |
airSensors |
TLM0100 |
2021-09-08T14:22:27Z |
0.313 |
| *_field |
*_measurement |
*sensorID |
_time |
_value |
| humidity |
airSensors |
TLM0100 |
2021-09-08T14:21:57Z |
36.03 |
| humidity |
airSensors |
TLM0100 |
2021-09-08T14:22:07Z |
36.07 |
| humidity |
airSensors |
TLM0100 |
2021-09-08T14:22:17Z |
36.1 |
| humidity |
airSensors |
TLM0100 |
2021-09-08T14:22:27Z |
36.12 |
| *_field |
*_measurement |
*sensorID |
_time |
_value |
| temperature |
airSensors |
TLM0100 |
2021-09-08T14:21:57Z |
70.84 |
| temperature |
airSensors |
TLM0100 |
2021-09-08T14:22:07Z |
70.86 |
| temperature |
airSensors |
TLM0100 |
2021-09-08T14:22:17Z |
70.89 |
| temperature |
airSensors |
TLM0100 |
2021-09-08T14:22:27Z |
70.85 |
Output data
| *_field |
*_measurement |
*sensorID |
_value |
| co |
airSensors |
TLM0100 |
_field |
| co |
airSensors |
TLM0100 |
_measurement |
| co |
airSensors |
TLM0100 |
sensorID |
| *_field |
*_measurement |
*sensorID |
_value |
| humidity |
airSensors |
TLM0100 |
_field |
| humidity |
airSensors |
TLM0100 |
_measurement |
| humidity |
airSensors |
TLM0100 |
sensorID |
| *_field |
*_measurement |
*sensorID |
_value |
| temperature |
airSensors |
TLM0100 |
_field |
| temperature |
airSensors |
TLM0100 |
_measurement |
| temperature |
airSensors |
TLM0100 |
sensorID |
{{% /expand %}}
{{< /expand-wrapper >}}
Return all distinct group key columns in a single table
data
|> keys()
|> keep(columns: ["_value"])
|> distinct()
{{< expand-wrapper >}}
{{% expand "View example input and output" %}}
Input data
| *_field |
*_measurement |
*sensorID |
_time |
_value |
| co |
airSensors |
TLM0100 |
2021-09-08T14:21:57Z |
0.31 |
| co |
airSensors |
TLM0100 |
2021-09-08T14:22:07Z |
0.295 |
| co |
airSensors |
TLM0100 |
2021-09-08T14:22:17Z |
0.314 |
| co |
airSensors |
TLM0100 |
2021-09-08T14:22:27Z |
0.313 |
| *_field |
*_measurement |
*sensorID |
_time |
_value |
| humidity |
airSensors |
TLM0100 |
2021-09-08T14:21:57Z |
36.03 |
| humidity |
airSensors |
TLM0100 |
2021-09-08T14:22:07Z |
36.07 |
| humidity |
airSensors |
TLM0100 |
2021-09-08T14:22:17Z |
36.1 |
| humidity |
airSensors |
TLM0100 |
2021-09-08T14:22:27Z |
36.12 |
| *_field |
*_measurement |
*sensorID |
_time |
_value |
| temperature |
airSensors |
TLM0100 |
2021-09-08T14:21:57Z |
70.84 |
| temperature |
airSensors |
TLM0100 |
2021-09-08T14:22:07Z |
70.86 |
| temperature |
airSensors |
TLM0100 |
2021-09-08T14:22:17Z |
70.89 |
| temperature |
airSensors |
TLM0100 |
2021-09-08T14:22:27Z |
70.85 |
Output data
| _value |
| _field |
| _measurement |
| sensorID |
{{% /expand %}}
{{< /expand-wrapper >}}
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 "sampledata"
sampledata.int()
|> keys()
|> findColumn(fn: (key) => true, column: "_value")// Returns [tag]