跳转至

Pivot(数据透视(Pivot))

Supported in: Streaming

Apply an aggregate expression in a pivot context. The aggregation will run as a set of separate aggregations scoped to each distinct value of the pivot expression. The output is a map from pivot value to aggregate expression value.

Expression categories: Aggregate

Declared arguments

  • Aggregate expression: The aggregate expression to apply.
    Expression\
  • Pivot expression: The pivot expression to apply.
    Expression\

Type variable bounds: K accepts ComparableType**V accepts AnyType

Output type: Map\

Examples

Example 1: Base case

Argument values:

  • Aggregate expression:
    sum(
     expression: value,
    )
  • Pivot expression: pivot

Given input table:

pivot value
a 1
b 2
a 3

Outputs: {
 a -> 4,
 b -> 2,
}


Example 2: Base case

Argument values:

  • Aggregate expression:
    sum(
     expression: value,
    )
  • Pivot expression:
    cleanString(
     cleanActions: {trim},
     expression: pivot,
    )

Given input table:

pivot value
a 1
b 2
a 3

Outputs: {
 a -> 4,
 b -> 2,
}



中文翻译


数据透视(Pivot)

支持流式处理(Streaming)

在数据透视上下文中应用聚合表达式。聚合操作将以一组独立的聚合形式运行,每个聚合作用于数据透视表达式(pivot expression)的每个不同值。输出结果是一个从透视值到聚合表达式值的映射(map)。

表达式类别: 聚合(Aggregate)

声明的参数

  • 聚合表达式(Aggregate expression): 要应用的聚合表达式。
    表达式\
  • 透视表达式(Pivot expression): 要应用的透视表达式。
    表达式\

类型变量约束: K 接受 ComparableType**V 接受 AnyType

输出类型: Map\

示例

示例 1:基础情况

参数值:

  • 聚合表达式:
    sum(
     expression: value,
    )
  • 透视表达式: pivot

输入表:

pivot value
a 1
b 2
a 3

输出结果: {
 a -> 4,
 b -> 2,
}


示例 2:基础情况

参数值:

  • 聚合表达式:
    sum(
     expression: value,
    )
  • 透视表达式:
    cleanString(
     cleanActions: {trim},
     expression: pivot,
    )

输入表:

pivot value
a 1
b 2
a 3

输出结果: {
 a -> 4,
 b -> 2,
}