Back to Influxdb

keyValues() function

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

latest3.8 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#L1372-L1378 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

keyValues() returns a stream of tables with each input tables' group key and two columns, _key and _value, that correspond to unique column label and value pairs for each input table.

Function type signature
js
(<-tables: stream[A], ?keyColumns: [string]) => stream[{B with _value: C, _key: string}] where A: Record, B: Record

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

keyColumns

List of columns from which values are extracted.

All columns must be of the same type. Each input table must have all of the columns in the keyColumns parameter.

tables

Input data. Default is piped-forward data (<-).

Examples

Get key values from explicitly defined columns

js
data
    |> keyValues(keyColumns: ["sensorID", "_field"])

{{< 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_key_value
coairSensorsTLM0100sensorIDTLM0100
coairSensorsTLM0100_fieldco
*_field*_measurement*sensorID_key_value
humidityairSensorsTLM0100sensorIDTLM0100
humidityairSensorsTLM0100_fieldhumidity
*_field*_measurement*sensorID_key_value
temperatureairSensorsTLM0100sensorIDTLM0100
temperatureairSensorsTLM0100_fieldtemperature

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