Back to Influxdb

experimental.unpivot() function

content/flux/v0/stdlib/experimental/unpivot.md

latest3.1 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/experimental/experimental.flux#L1350-L1356 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

experimental.unpivot() creates _field and _value columns pairs using all columns (other than _time) not in the group key. The _field column contains the original column label and the _value column contains the original column value.

The output stream retains the group key and all group key columns of the input stream. _field is added to the output group key.

Function type signature
js
(<-tables: stream[{A with _time: time}], ?otherColumns: [string]) => stream[{B with _value: C, _field: string}] where A: Record, B: Record

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

tables

Input data. Default is piped-forward data (<-).

otherColumns

List of column names that are not in the group key but are also not field columns. Default is ["_time"].

Examples

Unpivot data into _field and _value columns

js
import "experimental"

data
    |> experimental.unpivot()

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time*locationtemphum
2022-01-01T00:00:00ZDenver10.281.5
2022-01-02T00:00:00ZDenver12.441.3
_time*locationtemphum
2022-01-01T00:00:00ZNew York50.199.2
2022-01-02T00:00:00ZNew York55.897.7

Output data

*location*_field_time_value
Denverhum2022-01-01T00:00:00Z81.5
Denverhum2022-01-02T00:00:00Z41.3
*location*_field_time_value
New Yorkhum2022-01-01T00:00:00Z99.2
New Yorkhum2022-01-02T00:00:00Z97.7
*location*_field_time_value
Denvertemp2022-01-01T00:00:00Z10.2
Denvertemp2022-01-02T00:00:00Z12.4
*location*_field_time_value
New Yorktemp2022-01-01T00:00:00Z50.1
New Yorktemp2022-01-02T00:00:00Z55.8

{{% /expand %}} {{< /expand-wrapper >}}