Documentation

keys() function

Flux 0.13.0+

The keys() function outputs the column keys in the group key of each input table. For each input table, the function outputs a table with the same group key columns, and a _value column containing the labels of the input table’s group key. Each row in an output table contains the group key value and the label of one column in the group key of the input table. Each output table has the same number of rows as the size of the group key of the input table.

keys(column: "_value")

Parameters

column

Name of the output column in to store group key labels in. Default is “_value”`.

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.

Return group key columns for each input table

import "influxdata/influxdb/sample"

data = sample.data(set: "airSensor") 
  |> range(start: -30m)
  |> filter(fn: (r) => r.sensor_id == "TLM0100")

data
  |> keys()

View example input and output

Return all distinct group key columns in a single table

import "influxdata/influxdb/sample"

data = sample.data(set: "airSensor") 
  |> range(start: -30m)
  |> filter(fn: (r) => r.sensor_id == "TLM0100")

data
  |> keys()
  |> keep(columns: ["_value"])
  |> distinct()

View example input and output

Return group key columns as an array

To return group key columns as an array:

  1. Use keys() to replace the _value column with the group key labels.
  2. Use findColumn() to return the _value column as an array.
import "influxdata/influxdb/sample"

data = sample.data(set: "airSensor") 
  |> range(start: -30m)
  |> filter(fn: (r) => r.sensor_id == "TLM0100")

data
  |> keys()
  |> findColumn(fn: (key) => true, column: "_value")

// Returns [_start, _stop, _field, _measurement, sensor_id]

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.