跳转至

Unpivot(逆透视(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. All other columns that are not unpivoted are kept as is.

Transform categories: Aggregate, Popular

Declared arguments

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

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:

airline new_york_miles london_miles
foundry airways 1000 6000
new air null 8000

Output:

city miles airline
new_york_miles 1000 foundry airways
london_miles 6000 foundry airways
new_york_miles null new air
london_miles 8000 new 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:

airline new_york_miles london_miles miles
foundry airways 1000 6000 0
new air null 8000 0

Output:

city miles airline
new_york_miles 1000 foundry airways
london_miles 6000 foundry airways
new_york_miles null new air
london_miles 8000 new air


中文翻译


逆透视(Unpivot)

支持环境:批处理(Batch)、快速处理(Faster)、流处理(Streaming)

逆透视是透视(pivot)的逆向操作。该操作将多列数据转换为行数据,将数据从宽格式(wide format)转换为长格式(long format)。具体实现时,会创建两个新列:一个列包含原始列名作为值,另一个列包含对应的数据值。所有未被逆透视的列将保持原样。

转换类别:聚合(Aggregate)、常用(Popular)

声明参数

  • 待逆透视列(Columns to unpivot): 需要进行逆透视的列列表。
    List\>
  • 数据集(Dataset): 执行逆透视操作的数据集。
    Table
  • 名称列(Name column): 输出列,包含原始数据集中的列名。
    Literal\
  • 值列(Value column): 输出列,包含原始数据集中的值。
    Literal\

类型变量约束: T 接受任意类型(AnyType)

示例

示例 1:基础案例

参数值:

  • 待逆透视列: [new_york_miles, london_miles]
  • 数据集: ri.foundry.main.dataset.a
  • 名称列: city
  • 值列: miles

输入:

airline new_york_miles london_miles
foundry airways 1000 6000
new air null 8000

输出:

city miles airline
new_york_miles 1000 foundry airways
london_miles 6000 foundry airways
new_york_miles null new air
london_miles 8000 new air

示例 2:基础案例

参数值:

  • 待逆透视列: [new_york_miles, london_miles]
  • 数据集: ri.foundry.main.dataset.a
  • 名称列: city
  • 值列: miles

输入:

airline new_york_miles london_miles miles
foundry airways 1000 6000 0
new air null 8000 0

输出:

city miles airline
new_york_miles 1000 foundry airways
london_miles 6000 foundry airways
new_york_miles null new air
london_miles 8000 new air