Partition array

Supported in: Batch, Streaming

Splits an array into consecutive arrays of at most the given size, preserving element order. The size must be a positive integer. Returns null if the array or size is null, or the size is invalid.

Expression categories: Array

Declared arguments

  • Array: Array to partition.
    Expression<Array<T>>
  • Size: Maximum number of elements in each partition. Must be a positive integer.
    Expression<Integer>

Type variable bounds: T accepts AnyType

Output type: Array<Array<T>>

Examples

Example 1: Base case

Argument values:

  • Array: [ a, b, c, d, e ]
  • Size: 2

Output: [ [ a, b ], [ c, d ], [ e ] ]


Example 2: Null case

Argument values:

  • Array: array
  • Size: size
arraysizeOutput
null2null
[ 1 ]nullnull
[ 1 ]0null
[ 1 ]-1null
[ ]0null
[ 1, null, 3 ]2[ [ 1, null ], [ 3 ] ]

Example 3: Edge case

Argument values:

  • Array: array
  • Size: size
arraysizeOutput
[ ]2[ ]
[ 1, 2 ]1[ [ 1 ], [ 2 ] ]
[ 1, 2, 3, 4 ]2[ [ 1, 2 ], [ 3, 4 ] ]
[ 1, 2, 3 ]2[ [ 1, 2 ], [ 3 ] ]
[ 1, 2 ]2[ [ 1, 2 ] ]
[ 1, 2 ]2147483647[ [ 1, 2 ] ]