Documentation

keyValues() function

Flux 0.13.0+

The keyValues() function returns a table with the input table’s group key plus two columns, _key and _value, that correspond to unique column and value pairs for specific columns in each input table.

keyValues(keyColumns: ["usage_idle", "usage_user"])

Parameters

keyColumns

A list of columns from which values are extracted. All columns indicated must be of the same type. Each input table must have all of the columns listed by the keyColumns parameter.

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.

Get key values from explicitly defined columns

import "influxdata/influxdb/sample"

data = sample.data(set: "airSensor") 
  |> filter(fn: (r) => r.sensor_id == "TLM0100")

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

View example input and output

Get key values from all group key columns

  1. Use keys() and findColumn() to extract an array of group key columns and store it as a variable.
  2. Use keyValues() and provide the group key column array variable to the keyColumns parameter.
import "influxdata/influxdb/sample"

data = sample.data(set: "airSensor") 
  |> filter(fn: (r) => r.sensor_id == "TLM0100")

keyColumns = data
  |> keys()
  |> findColumn(fn: (key) => true, column: "_value")
  // Returns [_field, _measurement, sensor_id]

data
  |> keyValues(keyColumns: keyColumns)

View example input and output


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.