Documentation

schema.fieldsAsCols() function

The schema.fieldsAsCols() function is a special application of the pivot() function that pivots on _field and _time columns to aligns fields within each input table that have the same timestamp.

Function type: Transformation

import "influxdata/influxdb/schema"

schema.fieldsAsCols()

Examples

import "influxdata/influxdb/schema"

from(bucket:"example-bucket")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "cpu")
  |> schema.fieldsAsCols()
  |> keep(columns: ["_time", "cpu", "usage_idle", "usage_user"])

Function definition

package schema

fieldsAsCols = (tables=<-) =>
  tables
    |> pivot(
      rowKey:["_time"],
      columnKey: ["_field"],
      valueColumn: "_value"
    )

Used functions: pivot()


New! Cloud or OSS?

InfluxDB OSS 2.0 now generally available!

InfluxDB OSS 2.0 is now generally available and ready for production use. See the InfluxDB OSS 2.0 release notes.

For information about upgrading to InfluxDB OSS 2.0, see: