Creates a map based on Array a and Array b.
Syntax
map<K, V> map_from_arrays([string <mapDupKeyPolicy>,] array<K> <a>, array<V> <b>))
Parameters
mapDupKeyPolicy: optional. A value of the STRING type. This parameter specifies the method that is used to process duplicate keys. Valid values:
exception: An error is returned.
last_win: The latter key overwrites the former key.
You can also specify the
odps.sql.map.key.dedup.policy
parameter at the session level to configure the method that is used to process duplicate keys. For example, you can setodps.sql.map.key.dedup.policy
to exception. If you do not specify this parameter, the default value last_win is used.NoteThe behavior implementation of MaxCompute is determined based on mapDupKeyPolicy. If you do not specify mapDupKeyPolicy, the value of
odps.sql.map.key.dedup.policy
is used.a: required. This parameter specifies an array. This parameter corresponds to the key in the generated map.
K
inarray<K>
specifies the data type of the elements in the array. The elements can be of any data type.b: required. This parameter specifies an array. This parameter corresponds to the value in the generated map.
V
inarray<V>
specifies the data type of the elements in the array. The elements can be of any data type.
Return value
A value of the MAP type is returned. The return value varies based on the following rules:
If Array a or Array b is null, null is returned.
If Array a contains a null element or the two arrays are of different lengths, an error is returned.
Examples
-- The return value is {1:2, 3:4}.
select map_from_arrays(array(1.0, 3.0), array('2', '4'));
-- The return value is {1:2, 3:6}.
select map_from_arrays('last_win', array(1.0, 3.0, 3), array('2', '4', '6'));
Related functions
MAP_FROM_ARRAYS is a complex type function. For more information about the functions that are used to process data of complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.