keyValues() function

Warning! This page documents an earlier version of Flux, which is no longer actively developed. Flux v0.36 is the most recent stable version of Flux.

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. Each input table must have all of the columns listed by the keyColumns parameter.

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

Additional requirements

  • Only one of keyColumns or fn may be used in a single call.
  • All columns indicated must be of the same type.
  • Each input table must have all of the columns listed by the keyColumns parameter.

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