keyValues() function

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

Function type: Transformation
Output data type: Object

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

// OR

keyValues(fn: (schema) => schema.columns |> filter(fn: (r) =>  r.label =~ /usage_.*/))

Parameters

keyColumns and fn are mutually exclusive. Only one may be used at a time.

keyColumns

A list of columns from which values are extracted. All columns indicated must be of the same type.

Data type: Array of strings

fn

Function used to identify a set of columns. All columns indicated must be of the same type.

Data type: Function

Examples

Get key values from explicitly defined columns
from(bucket: "telegraf/autogen")
  |> range(start: -30m)
  |> filter(fn: (r) => r._measurement == "cpu")
  |> keyValues(keyColumns: ["usage_idle", "usage_user"])
Get key values from columns matching a regular expression
from(bucket: "telegraf/autogen")
  |> range(start: -30m)
  |> filter(fn: (r) => r._measurement == "cpu")
  |> keyValues(fn: (schema) => schema.columns |> filter(fn: (r) =>  r.label =~ /usage_.*/))

SHOW MEASUREMENTS
SHOW FIELD KEYS
SHOW TAG KEYS
SHOW TAG VALUES
SHOW SERIES

This documentation is open source. See a typo? Please, open an issue.


Need help getting up and running? Get Support