Back to Influxdb

keys() function

content/flux/v0/stdlib/universe/keys.md

latest6.0 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/universe/universe.flux#L1610-L1610 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.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.

Function type signature
js
(<-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

js
data
    |> keys()

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

Input data

*_field*_measurement*sensorID_time_value
coairSensorsTLM01002021-09-08T14:21:57Z0.31
coairSensorsTLM01002021-09-08T14:22:07Z0.295
coairSensorsTLM01002021-09-08T14:22:17Z0.314
coairSensorsTLM01002021-09-08T14:22:27Z0.313
*_field*_measurement*sensorID_time_value
humidityairSensorsTLM01002021-09-08T14:21:57Z36.03
humidityairSensorsTLM01002021-09-08T14:22:07Z36.07
humidityairSensorsTLM01002021-09-08T14:22:17Z36.1
humidityairSensorsTLM01002021-09-08T14:22:27Z36.12
*_field*_measurement*sensorID_time_value
temperatureairSensorsTLM01002021-09-08T14:21:57Z70.84
temperatureairSensorsTLM01002021-09-08T14:22:07Z70.86
temperatureairSensorsTLM01002021-09-08T14:22:17Z70.89
temperatureairSensorsTLM01002021-09-08T14:22:27Z70.85

Output data

*_field*_measurement*sensorID_value
coairSensorsTLM0100_field
coairSensorsTLM0100_measurement
coairSensorsTLM0100sensorID
*_field*_measurement*sensorID_value
humidityairSensorsTLM0100_field
humidityairSensorsTLM0100_measurement
humidityairSensorsTLM0100sensorID
*_field*_measurement*sensorID_value
temperatureairSensorsTLM0100_field
temperatureairSensorsTLM0100_measurement
temperatureairSensorsTLM0100sensorID

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

Return all distinct group key columns in a single table

js
data
    |> keys()
    |> keep(columns: ["_value"])
    |> distinct()

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

Input data

*_field*_measurement*sensorID_time_value
coairSensorsTLM01002021-09-08T14:21:57Z0.31
coairSensorsTLM01002021-09-08T14:22:07Z0.295
coairSensorsTLM01002021-09-08T14:22:17Z0.314
coairSensorsTLM01002021-09-08T14:22:27Z0.313
*_field*_measurement*sensorID_time_value
humidityairSensorsTLM01002021-09-08T14:21:57Z36.03
humidityairSensorsTLM01002021-09-08T14:22:07Z36.07
humidityairSensorsTLM01002021-09-08T14:22:17Z36.1
humidityairSensorsTLM01002021-09-08T14:22:27Z36.12
*_field*_measurement*sensorID_time_value
temperatureairSensorsTLM01002021-09-08T14:21:57Z70.84
temperatureairSensorsTLM01002021-09-08T14:22:07Z70.86
temperatureairSensorsTLM01002021-09-08T14:22:17Z70.89
temperatureairSensorsTLM01002021-09-08T14:22:27Z70.85

Output data

_value
_field
_measurement
sensorID

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

Return group key columns as an array

  1. Use keys() to replace the _value column with the group key labels.
  2. Use findColumn() to return the _value column as an array.
js
import "sampledata"

sampledata.int()
    |> keys()
    |> findColumn(fn: (key) => true, column: "_value")// Returns [tag]