docs-v2/content/v2.0/reference/flux/stdlib/built-in/transformations/keyvalues.md

2.9 KiB
Raw Blame History

title description aliases menu weight related
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.
/v2.0/reference/flux/functions/transformations/keyvalues
/v2.0/reference/flux/functions/built-in/transformations/keyvalues/
v2_0_ref
name parent
keyValues built-in-transformations
402
https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-measurements, InfluxQL  SHOW MEASUREMENTS
https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-field-keys, InfluxQL  SHOW FIELD KEYS
https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-tag-keys, InfluxQL  SHOW TAG KEYS
https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-tag-values, InfluxQL  SHOW TAG VALUES
https://docs.influxdata.com/influxdb/latest/query_language/schema_exploration/#show-serie, InfluxQL  SHOW SERIES

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

{{% note %}} keyColumns and fn are mutually exclusive. Only one may be used at a time. {{% /note %}}

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.

{{% note %}} Make sure fn parameter names match each specified parameter. To learn why, see Match parameter names. {{% /note %}}

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: "example-bucket")
  |> 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: "example-bucket")
  |> range(start: -30m)
  |> filter(fn: (r) => r._measurement == "cpu")
  |> keyValues(fn: (schema) => schema.columns |> filter(fn: (r) =>  r.label =~ /usage_.*/))