content/flux/v0/stdlib/universe/keys.md
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.
(<-tables: stream[A], ?column: string) => stream[B] where A: Record, B: Record
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
Column to store group key labels in. Default is _value.
Input data. Default is piped-forward data (<-).
data
|> keys()
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| *_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 |
| *_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 >}}
data
|> keys()
|> keep(columns: ["_value"])
|> distinct()
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| *_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 |
| _value |
|---|
| _field |
| _measurement |
| sensorID |
{{% /expand %}} {{< /expand-wrapper >}}
keys() to replace the _value column with the group key labels.findColumn() to return the _value column as an array.import "sampledata"
sampledata.int()
|> keys()
|> findColumn(fn: (key) => true, column: "_value")// Returns [tag]