跳转至

Create map from arrays(从数组创建映射(Map))

Supported in: Batch, Faster, 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 of values: Array used as values for the output map.
    Expression\>

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

Output type: Map\

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_array second_array Output
[ 1, 2, 3 ] null null
null [ 1, 2, 3 ] null
null null null

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 ],
}



中文翻译

从数组创建映射(Map)

支持模式:批处理(Batch)、快速处理(Faster)、流处理(Streaming)

通过压缩后的数组中的键值对返回一个映射(Map)。空值(Null)不允许作为键,否则将导致运行时错误。

表达式类别: 数组(Array)、映射(Map)

声明参数

  • 键数组(Array of keys): 用作输出映射键的数组。
    表达式\>
  • 值数组(Array of values): 用作输出映射值的数组。
    表达式\>

类型变量约束: K 接受任意类型(AnyType)**V 接受任意类型(AnyType)

输出类型: Map\

示例

示例1:基础情况

参数值:

  • 键数组: [ 1, 2, 3 ]
  • 值数组: [ 4, 5, 6 ]

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


示例2:基础情况

描述: 左侧数组中的重复项将被移除,保留最后出现的键值对。

参数值:

  • 键数组: [ 1, 1, 2, 3 ]
  • 值数组: [ 4, 5, 6, 7 ]

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


示例3:空值情况

描述: 如果值的数量多于键的数量,则输出为空值(null)

参数值:

  • 键数组: [ 1, 2 ]
  • 值数组: [ 5, 6, 7, 9 ]

输出: null


示例4:空值情况

描述: 如果键的数量多于值的数量,则输出为空值(null)

参数值:

  • 键数组: [ 1, 2, 3, 4 ]
  • 值数组: [ 5, 6, 7 ]

输出: null


示例5:空值情况

参数值:

  • 键数组: first_array
  • 值数组: second_array
first_array second_array 输出(Output)
[ 1, 2, 3 ] null null
null [ 1, 2, 3 ] null
null null null

示例6:空值情况

描述: 当任意键为空值(null)时应返回空值(null)

参数值:

  • 键数组: [ null, 2, 3 ]
  • 值数组: [ 4, 5, 6 ]

输出: null


示例7:空值情况

描述: 允许空值(null)作为值

参数值:

  • 键数组: [ 1, 2, 3 ]
  • 值数组: [ 4, null, 6 ]

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


示例8:边界情况

描述: 允许数组作为键

参数值:

  • 键数组: [ [ 1, 2 ], [ 3, 4 ] ]
  • 值数组: [ 5, 6 ]

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


示例9:边界情况

描述: 允许数组作为值

参数值:

  • 键数组: [ 1, 2 ]
  • 值数组: [ [ 3, 4 ], [ 5, 6 ] ]

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