Array add(数组添加(Array add))¶
Supported in: Batch, Faster, Streaming
Adds a value to the array at a specified index.
Expression categories: Array
Declared arguments¶
- Array: The array to add an element to.
Expression\> - Index: Position where the new element should be inserted into the array. First element is at position 1.
Expression\ - Value: The element to add to the array.
Expression\
Type variable bounds: T accepts AnyType
Output type: Array\
Examples¶
Example 1: Base case¶
Argument values:
- Array:
numbers - Index: 1
- Value: 1
| numbers | Output |
|---|---|
| [ 3, 5 ] | [ 1, 3, 5 ] |
| [ 2 ] | [ 1, 2 ] |
| [ ] | [ 1 ] |
Example 2: Null case¶
Argument values:
- Array:
numbers - Index:
index - Value:
value
| numbers | value | index | Output |
|---|---|---|---|
| null | 1 | 1 | null |
| [ 1 ] | null | 1 | [ null, 1 ] |
| [ 1 ] | 1 | null | [ 1 ] |
Example 3: Edge case¶
Description: Index values greater than the list length append to the array.
Argument values:
- Array:
numbers - Index:
index - Value:
value
| numbers | value | index | Output |
|---|---|---|---|
| [ 1, 2 ] | 3 | 3 | [ 1, 2, 3 ] |
| [ 1 ] | 2 | 3 | [ 1, null, 2 ] |
| [ ] | 1 | 3 | [ null, null, 1 ] |
| [ 3, 5 ] | 1 | 10 | [ 3, 5, null, null, null, null, null, null, null, 1 ] |
Example 4: Edge case¶
Description: Negative values for the index count back from the end of the array.
Argument values:
- Array:
numbers - Index:
index - Value:
value
| numbers | value | index | Output |
|---|---|---|---|
| [ 1, 3 ] | 2 | -1 | [ 1, 2, 3 ] |
| [ 2, 3 ] | 1 | -2 | [ 1, 2, 3 ] |
| [ 2, 3 ] | 1 | -3 | [ 1, null, 2, 3 ] |
| [ 2 ] | 1 | -1 | [ 1, 2 ] |
| [ 2 ] | 1 | -2 | [ 1, null, 2 ] |
| [ 2 ] | 1 | -3 | [ 1, null, null, 2 ] |
| [ ] | 1 | -1 | [ 1, null ] |
| [ ] | 1 | -2 | [ 1, null, null ] |
| [ ] | 1 | -3 | [ 1, null, null, null ] |
中文翻译¶
数组添加(Array add)¶
支持模式:批处理(Batch)、快速处理(Faster)、流处理(Streaming)
在数组的指定索引位置添加一个值。
表达式类别: 数组(Array)
声明的参数¶
- Array(数组): 需要添加元素的数组。
表达式\> - Index(索引): 新元素应插入数组的位置。第一个元素的位置为 1。
表达式\ - Value(值): 要添加到数组中的元素。
表达式\
类型变量约束: T 接受任意类型(AnyType)
输出类型: Array\
示例¶
示例 1:基础情况¶
参数值:
- Array(数组):
numbers - Index(索引): 1
- Value(值): 1
| numbers | 输出(Output) |
|---|---|
| [ 3, 5 ] | [ 1, 3, 5 ] |
| [ 2 ] | [ 1, 2 ] |
| [ ] | [ 1 ] |
示例 2:空值情况¶
参数值:
- Array(数组):
numbers - Index(索引):
index - Value(值):
value
| numbers | value | index | 输出(Output) |
|---|---|---|---|
| null | 1 | 1 | null |
| [ 1 ] | null | 1 | [ null, 1 ] |
| [ 1 ] | 1 | null | [ 1 ] |
示例 3:边界情况¶
描述: 索引值大于列表长度时,将元素追加到数组末尾。
参数值:
- Array(数组):
numbers - Index(索引):
index - Value(值):
value
| numbers | value | index | 输出(Output) |
|---|---|---|---|
| [ 1, 2 ] | 3 | 3 | [ 1, 2, 3 ] |
| [ 1 ] | 2 | 3 | [ 1, null, 2 ] |
| [ ] | 1 | 3 | [ null, null, 1 ] |
| [ 3, 5 ] | 1 | 10 | [ 3, 5, null, null, null, null, null, null, null, 1 ] |
示例 4:边界情况¶
描述: 索引为负值时,从数组末尾向前计数。
参数值:
- Array(数组):
numbers - Index(索引):
index - Value(值):
value
| numbers | value | index | 输出(Output) |
|---|---|---|---|
| [ 1, 3 ] | 2 | -1 | [ 1, 2, 3 ] |
| [ 2, 3 ] | 1 | -2 | [ 1, 2, 3 ] |
| [ 2, 3 ] | 1 | -3 | [ 1, null, 2, 3 ] |
| [ 2 ] | 1 | -1 | [ 1, 2 ] |
| [ 2 ] | 1 | -2 | [ 1, null, 2 ] |
| [ 2 ] | 1 | -3 | [ 1, null, null, 2 ] |
| [ ] | 1 | -1 | [ 1, null ] |
| [ ] | 1 | -2 | [ 1, null, null ] |
| [ ] | 1 | -3 | [ 1, null, null, null ] |