跳转至

Transform array element(转换数组元素(Transform array element))

Supported in: Batch, Streaming

Maps each element of an array using an expression. Note, array index starts at 1.

Expression categories: Array

Declared arguments

  • Array: Input array containing elements to apply the expression over.
    Expression\>
  • Expression to apply: The expression to apply once per element of the array.
    Expression\

Type variable bounds: T accepts AnyType

Output type: Array\

Examples

Example 1: Base case

Argument values:

  • Array: flight_number
  • Expression to apply:
    stringBeforeDelimiter(
     delimiter: -,
     expression: element,
     ignoreCase: false,
    )
flight_number Output
[ XB-134, MT-111 ] [ XB, MT ]

Example 2: Base case

Argument values:

  • Array: miles
  • Expression to apply:
    add(
     expressions: [previous_miles, element],
    )
miles previous_miles Output
[ 12300, 12342 ] 10000 [ 22300, 22342 ]

Example 3: Base case

Description: Add the index to the array element. Note the index starts at 1.

Argument values:

  • Array: array
  • Expression to apply:
    add(
     expressions: [elementIndex, element],
    )
array Output
[ 1, 1, 1 ] [ 2, 3, 4 ]

Example 4: Base case

Argument values:

  • Array: miles
  • Expression to apply:
    cast(
     expression: element,
     type: String,
    )
miles Output
[ 12300, 12342 ] [ 12300, 12342 ]

Example 5: Base case

Description: Getting the struct element from an array of structs.

Argument values:

  • Array: raw_data
  • Expression to apply:
    getStructField(
     locator: miles,
     struct: element,
    )
raw_data Output
[ {
miles: 22300,
tail_number: XB-112,
}, {
miles: 22342,
tail_number: XB-112,
} ]
[ 22300, 22342 ]

Example 6: Base case

Description: Getting the struct element from an array of structs.

Argument values:

  • Array: raw_data
  • Expression to apply:
    transformMapKeys(
     expression:
    uppercase(
     expression: key,
    ),
     map: element,
    )
raw_data Output
[ {
 miles -> 22300,
 tail_number -> XB-112,
}, {
 miles -> 22342L,
 tail_number -> XB-112,
} ]
[ {
 MILES -> 22300,
 TAIL_NUMBER -> XB-112,
}, {
 MILES -> 22342L,
 TAIL_NUMBER -> XB-112,
} ]


中文翻译

# 转换数组元素(Transform array element)

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

使用表达式映射数组中的每个元素。注意,数组索引从1开始。

**表达式类别:** 数组(Array)

## 声明的参数

* **数组(Array):** 包含要应用表达式的元素的输入数组。<br>*表达式\<数组\<任意类型>>*
* **要应用的表达式(Expression to apply):** 对数组中的每个元素应用一次的表达式。<br>*表达式\<T>*

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

**输出类型:** *数组\<T>*

## 示例

### 示例 1:基本情况

**参数值:**

* **数组(Array):** `flight_number`
* **要应用的表达式(Expression to apply):** <br>stringBeforeDelimiter(<br> delimiter: -,<br> expression: `element`,<br> ignoreCase: false,<br>)

| flight\_number | **输出(Output)** |
| ----- | ----- |
| \[ XB-134, MT-111 ] | \[ XB, MT ] |

***

### 示例 2:基本情况

**参数值:**

* **数组(Array):** `miles`
* **要应用的表达式(Expression to apply):** <br>add(<br> expressions: \[`previous_miles`, `element`],<br>)

| miles | previous\_miles | **输出(Output)** |
| ----- | ----- | ----- |
| \[ 12300, 12342 ] | 10000 | \[ 22300, 22342 ] |

***

### 示例 3:基本情况

**描述:** 将索引添加到数组元素中。注意索引从1开始。

**参数值:**

* **数组(Array):** `array`
* **要应用的表达式(Expression to apply):** <br>add(<br> expressions: \[`elementIndex`, `element`],<br>)

| array | **输出(Output)** |
| ----- | ----- |
| \[ 1, 1, 1 ] | \[ 2, 3, 4 ] |

***

### 示例 4:基本情况

**参数值:**

* **数组(Array):** `miles`
* **要应用的表达式(Expression to apply):** <br>cast(<br> expression: `element`,<br> type: String,<br>)

| miles | **输出(Output)** |
| ----- | ----- |
| \[ 12300, 12342 ] | \[ 12300, 12342 ] |

***

### 示例 5:基本情况

**描述:** 从结构体数组中获取结构体元素。

**参数值:**

* **数组(Array):** `raw_data`
* **要应用的表达式(Expression to apply):** <br>getStructField(<br> locator: miles,<br> struct: `element`,<br>)

| raw\_data | **输出(Output)** |
| ----- | ----- |
| \[ {<br> **miles**: 22300,<br> **tail\_number**: XB-112,<br>}, {<br> **miles**: 22342,<br> **tail\_number**: XB-112,<br>} ] | \[ 22300, 22342 ] |

***

### 示例 6:基本情况

**描述:** 从结构体数组中获取结构体元素。

**参数值:**

* **数组(Array):** `raw_data`
* **要应用的表达式(Expression to apply):** <br>transformMapKeys(<br> expression: <br>uppercase(<br> expression: `key`,<br>),<br> map: `element`,<br>)

| raw\_data | **输出(Output)** |
| ----- | ----- |
| \[ {<br> miles -> 22300,<br> tail\_number -> XB-112,<br>}, {<br> miles -> 22342L,<br> tail\_number -> XB-112,<br>} ] | \[ {<br> MILES -> 22300,<br> TAIL\_NUMBER -> XB-112,<br>}, {<br> MILES -> 22342L,<br> TAIL\_NUMBER -> XB-112,<br>} ] |

***