Data connectivity & integrationPipeline Builder TransformsUnpivot

Unpivot

Supported in: Batch, Faster, Streaming

Unpivot is the opposite operation of pivot. This converts multiple columns into rows, transforming data from a wide format to a long format. To do so it creates two new columns: one containing the original column names as values, and another containing the corresponding data values. Columns selected for unpivot have their values included even when their names match an output column name. Other columns are kept as is unless their names match an output column name, in which case they are replaced by the output column.

Transform categories: Aggregate, Popular

Declared arguments

  • Columns to unpivot: List of columns to unpivot.
    List<Column<T>>
  • Dataset: Dataset to perform unpivot on.
    Table
  • Name column: The output column that contains the column names from the original dataset.
    Literal<String>
  • Value column: The output column that contains the values from the original dataset.
    Literal<String>

Type variable bounds: T accepts AnyType

Examples

Example 1: Base case

Argument values:

  • Columns to unpivot: [new_york_miles, london_miles]
  • Dataset: ri.foundry.main.dataset.a
  • Name column: city
  • Value column: miles

Input:

airlinenew_york_mileslondon_miles
foundry airways10006000
new airnull8000

Output:

citymilesairline
new_york_miles1000foundry airways
london_miles6000foundry airways
new_york_milesnullnew air
london_miles8000new air

Example 2: Base case

Argument values:

  • Columns to unpivot: [new_york_miles, london_miles]
  • Dataset: ri.foundry.main.dataset.a
  • Name column: city
  • Value column: miles

Input:

airlinenew_york_mileslondon_milesmiles
foundry airways100060000
new airnull80000

Output:

citymilesairline
new_york_miles1000foundry airways
london_miles6000foundry airways
new_york_milesnullnew air
london_miles8000new air