2.8 KiB
title | description | aliases | menu | weight | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
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. |
|
|
401 |
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
orfn
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_.*/))
Related InfluxQL functions and statements:
SHOW MEASUREMENTS
SHOW FIELD KEYS
SHOW TAG KEYS
SHOW TAG VALUES
SHOW SERIES