Array element(数组元素(Array element))¶
Supported in: Batch, Faster, Streaming
Returns the element at a given position from the input array. Positions outside of the array will return null.
Expression categories: Array
Declared arguments¶
- Array: Array from which to extract element.
Expression\> - Position: Position of element to extract from array. First element is at position 1. If position is negative, accesses elements from last to first (example: -1 will return last element).
Expression\
Type variable bounds: T accepts AnyType
Output type: T
Examples¶
Example 1: Base case¶
Argument values:
- Array: [ 10, 11, 12 ]
- Position: 1
Output: 10
Example 2: Null case¶
Description: Output null if position greater than array length.
Argument values:
- Array: [ 1, 2, 4 ]
- Position: 10
Output: null
Example 3: Null case¶
Description: Index array from the end using negative index.
Argument values:
- Array: [ 1, 2, 4 ]
- Position: -1
Output: 4
Example 4: Null case¶
Argument values:
- Array:
array - Position:
position
| array | position | Output |
|---|---|---|
| [ 1, 2, 3 ] | null | null |
| null | 1 | null |
| null | null | null |
Example 5: Edge case¶
Argument values:
- Array:
array - Position:
position
| array | position | Output |
|---|---|---|
| [ 1, 2, 3 ] | 0 | null |
中文翻译¶
数组元素(Array element)¶
支持:批处理(Batch)、快速计算(Faster)、流处理(Streaming)
返回输入数组中指定位置的元素。超出数组范围的位置将返回 null。
表达式类别: 数组(Array)
声明的参数¶
- 数组(Array): 用于提取元素的数组。
表达式\> - 位置(Position): 要提取的元素在数组中的位置。第一个元素位于位置 1。如果位置为负数,则从末尾向前访问元素(例如:-1 将返回最后一个元素)。
表达式\
类型变量边界: T 接受任意类型(AnyType)
输出类型: T
示例¶
示例 1:基础情况¶
参数值:
- 数组: [ 10, 11, 12 ]
- 位置: 1
输出: 10
示例 2:空值情况¶
描述: 如果位置大于数组长度,则输出 null。
参数值:
- 数组: [ 1, 2, 4 ]
- 位置: 10
输出: null
示例 3:空值情况¶
描述: 使用负索引从末尾索引数组。
参数值:
- 数组: [ 1, 2, 4 ]
- 位置: -1
输出: 4
示例 4:空值情况¶
参数值:
- 数组:
array - 位置:
position
| array | position | 输出 |
|---|---|---|
| [ 1, 2, 3 ] | null | null |
| null | 1 | null |
| null | null | null |
示例 5:边界情况¶
参数值:
- 数组:
array - 位置:
position
| array | position | 输出 |
|---|---|---|
| [ 1, 2, 3 ] | 0 | null |