All Products
Search
Document Center

MaxCompute:MAP_FROM_ARRAYS

Last Updated:Sep 21, 2026

The MAP_FROM_ARRAYS function combines the arrays a and b into a MAP object.

Command format

MAP<K, V> MAP_FROM_ARRAYS([STRING <mapDupKeyPolicy>,] ARRAY<K> <a>, ARRAY<V> <b>)

Parameters

  • mapDupKeyPolicy: Optional. A STRING. Specifies how to handle duplicate keys. Valid values:

    • exception: If a duplicate key exists, an error is returned.

    • last_win: If a duplicate key exists, the later value overwrites the earlier value.

    This parameter can also be set at the session level using the odps.sql.map.key.dedup.policy parameter. For example, set odps.sql.map.key.dedup.policy=exception;. If this parameter is not set, the default value is last_win.

    Note

    MaxCompute prioritizes the value of mapDupKeyPolicy in the function. If mapDupKeyPolicy is not specified in the function, MaxCompute uses the value of the odps.sql.map.key.dedup.policy parameter.

  • a: Required. An ARRAY. This array provides the keys for the resulting MAP object. In array<K>, K represents the data type of the array elements, which can be of any data type.

  • b: Required. An ARRAY. This array provides the values for the resulting MAP object. In array<V>, V represents the data type of the array elements, which can be of any data type.

Return value

Returns a MAP object. The following rules apply:

  • If a or b is NULL, the function returns NULL.

  • If array a contains a NULL element or the two arrays have different lengths, an error is returned.

Examples

-- Returns {"1.0": "2", "3.0": "4"}.
SELECT MAP_FROM_ARRAYS(ARRAY(1.0, 3.0), ARRAY('2', '4'));

-- Returns {"1.0": "2", "3.0": "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 functions that process complex data types such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.