unpivot
unpivot [name_column: const string]?, [value_column: const string]?, [name_value: col storable]+
The unpivot verb rotates a table by transforming a list of columns into rows.
This verb can be used to turn a wide table (e.g. timestamp, percent_load, percent_mem, percent_disk) into a narrower table (e.g. timestamp, op, percent). unpivot is not the exact reverse of pivot as it cannot undo the aggregations done in pivot.
The arguments are as follows:
name_column: Specifies the name of the name column which stores the name of the column a value comes from. Must be a constant string. Optional. Default value isname.value_column: Specifies the name of the value column which stores values from each of thename_valuecolumns passed in. Must be a constant string. Optional. Default value isvalue.name_value_0, ..., name_value_n: List of columns to generate rows from.
Additional details:
- The
name_columnandvalue_columnarguments, if specified, need to be specified together - The name and value columns will be inserted where the first
name_valuecolumn used to be unpivotis not supported for resource datasetsunpivotwill drop the primary key and any candidate keysgroup_byandorder_byspecifications are not allowed
Categories
Accelerable
unpivot is always accelerable if the input is accelerable. A dataset that only uses accelerable verbs can be accelerated, making queries on the dataset respond faster.
Examples
unpivot percent_load, percent_mem, percent_disk
Consider the following input table A:
| timestamp | percent_load | percent_mem | percent_disk |
|---|---|---|---|
| 10/31/2023 13:51:27 | 3.57 | 41.72 | 54.71 |
| 10/31/2023 13:52:43 | 39.04 | 40.24 | 20.72 |
The above statement transforms table A to:
| timestamp | name | value |
|---|---|---|
| 10/31/2023 13:51:27 | "percent_load" | 3.57 |
| 10/31/2023 13:51:27 | "percent_mem" | 41.72 |
| 10/31/2023 13:51:27 | "percent_disk" | 54.71 |
| 10/31/2023 13:52:43 | "percent_load" | 39.04 |
| 10/31/2023 13:52:43 | "percent_mem" | 40.24 |
| 10/31/2023 13:52:43 | "percent_disk" | 20.71 |
unpivot "op", "percent", percent_load, percent_mem, percent_disk
The above statement transforms table A to:
| timestamp | op | percent |
|---|---|---|
| 10/31/2023 13:51:27 | "percent_load" | 3.57 |
| 10/31/2023 13:51:27 | "percent_mem" | 41.72 |
| 10/31/2023 13:51:27 | "percent_disk" | 54.71 |
| 10/31/2023 13:52:43 | "percent_load" | 39.04 |
| 10/31/2023 13:52:43 | "percent_mem" | 40.24 |
| 10/31/2023 13:52:43 | "percent_disk" | 20.71 |
Updated 8 days ago