跳转至

Explode array with position(带位置的数组展开(Explode array with position))

Supported in: Batch, Streaming

Explode array into a row per value as a struct containing the element's relative position in the array and the element itself.

Expression categories: Array

Declared arguments

  • Array: Array of values to explode.
    Expression\>
  • optional Keep empty / null arrays: If true, empty arrays and nulls will be kept as nulls in the output, otherwise they will be filtered.
    Literal\

Type variable bounds: T accepts AnyType

Output type: Struct\

Examples

Example 1: Base case

Argument values:

  • Array: array
  • Keep empty / null arrays: null

Given input table:

array
[ one, two, three ]
[ four, five ]

Expected output table: | array | | ----- | | {
 element -> one,
 position -> 1,
} | | {
 element -> two,
 position -> 2,
} | | {
 element -> three,
 position -> 3,
} | | {
 element -> four,
 position -> 1,
} | | {
 element -> five,
 position -> 2,
} |


Example 2: Edge case

Argument values:

  • Array: array
  • Keep empty / null arrays: false

Given input table:

array
[ one, two, three ]
[ ]
[ four, five ]
[ ]

Expected output table: | array | | ----- | | {
 element -> one,
 position -> 1,
} | | {
 element -> two,
 position -> 2,
} | | {
 element -> three,
 position -> 3,
} | | {
 element -> four,
 position -> 1,
} | | {
 element -> five,
 position -> 2,
} |


Example 3: Edge case

Argument values:

  • Array: array
  • Keep empty / null arrays: true

Given input table:

array
[ one, two, three ]
[ ]
[ four, five ]
[ ]

Expected output table: | array | | ----- | | {
 element -> one,
 position -> 1,
} | | {
 element -> two,
 position -> 2,
} | | {
 element -> three,
 position -> 3,
} | | {
 element -> null,
 position -> null,
} | | {
 element -> four,
 position -> 1,
} | | {
 element -> five,
 position -> 2,
} | | {
 element -> null,
 position -> null,
} |



中文翻译

带位置的数组展开(Explode array with position)

支持:批处理(Batch)、流处理(Streaming)

将数组展开为每行一个值,以结构体形式包含该元素在数组中的相对位置及元素本身。

表达式类别: 数组(Array)

声明参数

  • 数组(Array): 要展开的值数组。
    表达式\>
  • 可选 保留空/空值数组(Keep empty / null arrays): 若为true,空数组和空值将在输出中保留为空值,否则将被过滤掉。
    字面量\

类型变量边界: T 接受任意类型(AnyType)

输出类型: 结构体\<可选[位置(position)]:整数(Integer), 可选[元素(element)]:T>

示例

示例1:基础情况

参数值:

  • 数组(Array): array
  • 保留空/空值数组(Keep empty / null arrays): null

给定输入表:

array
[ one, two, three ]
[ four, five ]

预期输出表: | array | | ----- | | {
 element -> one,
 position -> 1,
} | | {
 element -> two,
 position -> 2,
} | | {
 element -> three,
 position -> 3,
} | | {
 element -> four,
 position -> 1,
} | | {
 element -> five,
 position -> 2,
} |


示例2:边界情况

参数值:

  • 数组(Array): array
  • 保留空/空值数组(Keep empty / null arrays): false

给定输入表:

array
[ one, two, three ]
[ ]
[ four, five ]
[ ]

预期输出表: | array | | ----- | | {
 element -> one,
 position -> 1,
} | | {
 element -> two,
 position -> 2,
} | | {
 element -> three,
 position -> 3,
} | | {
 element -> four,
 position -> 1,
} | | {
 element -> five,
 position -> 2,
} |


示例3:边界情况

参数值:

  • 数组(Array): array
  • 保留空/空值数组(Keep empty / null arrays): true

给定输入表:

array
[ one, two, three ]
[ ]
[ four, five ]
[ ]

预期输出表: | array | | ----- | | {
 element -> one,
 position -> 1,
} | | {
 element -> two,
 position -> 2,
} | | {
 element -> three,
 position -> 3,
} | | {
 element -> null,
 position -> null,
} | | {
 element -> four,
 position -> 1,
} | | {
 element -> five,
 position -> 2,
} | | {
 element -> null,
 position -> null,
} |