Filter array elements

Supported in: Batch, Streaming

Filters an array based on the filter expression. Note, array index starts at 1.

Expression categories: Array

Declared arguments

  • Array - Array to be filtered.
    Expression<Array<T>>
  • Expression to filter - If the expression evaluates to true for a given element, the element will be kept, if false the element will be removed.
    Expression<Boolean>

Type variable bounds: T accepts AnyType

Output type: Array<T>

Examples

Example 1: Base case

Argument values:

  • Array: array
  • Expression to filter:
    isNotNull(
     expression: element,
    )
arrayOutput
[ 2, 5, null, 11 ][ 2, 5, 11 ]

Example 2: Base case

Argument values:

  • Array: array
  • Expression to filter:
    lessThanOrEquals(
     left: element,
     right: 10,
    )
arrayOutput
[ 2, 5, null, 11 ][ 2, 5 ]

Example 3: Base case

Argument values:

  • Array: array
  • Expression to filter:
    lessThanOrEquals(
     left: element,
     right: 10,
    )
arrayOutput
[ 2, 5, 7, 11, 12, 15 ][ 2, 5, 7 ]

Example 4: Base case

Description: Note that array index starts at 1. Argument values:

  • Array: array
  • Expression to filter:
    equals(
     left: element,
     right: elementIndex,
    )
arrayOutput
[ 1, -1, -2, 4, -5 ][ 1, 4 ]

Example 5: Base case

Argument values:

  • Array: array
  • Expression to filter:
    stringContains(
     expression: element,
     ignoreCase: false,
     value: hello,
    )
arrayOutput
[ hello world, hello, world ][ hello world, hello ]

Example 6: Base case

Argument values:

  • Array: array
  • Expression to filter:
    lessThanOrEquals(
     left:
    add(
     expressions: [element, 4],
    ),
     right: 10,
    )
arrayOutput
[ 2, 5, 7, 11, 12, 15 ][ 2, 5 ]

Example 7: Null case

Argument values:

  • Array: array
  • Expression to filter:
    lessThanOrEquals(
     left: element,
     right: 10,
    )
arrayOutput
nullnull