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<Array<AnyType>>
  • Expression to apply. - The expression to apply once per element of the array.
    Expression<T>

Type variable bounds: T accepts AnyType

Output type: Array<T>

Examples

Example 1: Base case

Argument values:

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

Example 2: Base case

Argument values:

  • Array: miles
  • Expression to apply.:
    add(
     expressions: [previous_miles, element],
    )
milesprevious_milesOutput
[ 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],
    )
arrayOutput
[ 1, 1, 1 ][ 2, 3, 4 ]

Example 4: Base case

Argument values:

  • Array: miles
  • Expression to apply.:
    cast(
     expression: element,
     type: String,
    )
milesOutput
[ 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_dataOutput
[ {
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_dataOutput
[ {
 miles -> 22300,
 tail_number -> XB-112,
}, {
 miles -> 22342L,
 tail_number -> XB-112,
} ]
[ {
 MILES -> 22300,
 TAIL_NUMBER -> XB-112,
}, {
 MILES -> 22342L,
 TAIL_NUMBER -> XB-112,
} ]