Create map from arrays

Supported in: Batch, Streaming

Returns a map using key-value pairs from the zipped arrays. Null values are not allowed as keys and will cause a runtime error.

Expression categories: Array, Map

Declared arguments

  • Array of keys - Array used as keys for the output map.
    Expression<Array<K>>
  • Array of values - Array used as values for the output map.
    Expression<Array<V>>

Type variable bounds: K accepts AnyType**V accepts AnyType

Output type: Map<K, V>

Examples

Example 1: Base case

Argument values:

  • Array of keys: [ 1, 2, 3 ]
  • Array of values: [ 4, 5, 6 ]

Output: {
 1 -> 4,
 2 -> 5,
 3 -> 6,
}


Example 2: Base case

Description: Duplicates in the left array will be removed, keeping the last seen key-value pair. Argument values:

  • Array of keys: [ 1, 1, 2, 3 ]
  • Array of values: [ 4, 5, 6, 7 ]

Output: {
 1 -> 5,
 2 -> 6,
 3 -> 7,
}


Example 3: Null case

Description: If there are more values than keys, the output is null Argument values:

  • Array of keys: [ 1, 2 ]
  • Array of values: [ 5, 6, 7, 9 ]

Output: null


Example 4: Null case

Description: If there are more keys than values, the output is null Argument values:

  • Array of keys: [ 1, 2, 3, 4 ]
  • Array of values: [ 5, 6, 7 ]

Output: null


Example 5: Null case

Argument values:

  • Array of keys: first_array
  • Array of values: second_array
first_arraysecond_arrayOutput
[ 1, 2, 3 ]nullnull
null[ 1, 2, 3 ]null
nullnullnull

Example 6: Null case

Description: Should return null when any key is null Argument values:

  • Array of keys: [ null, 2, 3 ]
  • Array of values: [ 4, 5, 6 ]

Output: null


Example 7: Null case

Description: Should allow null as a value Argument values:

  • Array of keys: [ 1, 2, 3 ]
  • Array of values: [ 4, null, 6 ]

Output: {
 1 -> 4,
 2 -> null,
 3 -> 6,
}


Example 8: Edge case

Description: Allows arrays as keys Argument values:

  • Array of keys: [ [ 1, 2 ], [ 3, 4 ] ]
  • Array of values: [ 5, 6 ]

Output: {
 [ 1, 2 ] -> 5,
 [ 3, 4 ] -> 6,
}


Example 9: Edge case

Description: Allows arrays as values Argument values:

  • Array of keys: [ 1, 2 ]
  • Array of values: [ [ 3, 4 ], [ 5, 6 ] ]

Output: {
 1 -> [ 3, 4 ],
 2 -> [ 5, 6 ],
}