All Products
Search
Document Center

MaxCompute:MAP_CONCAT

Last Updated:Aug 16, 2023

Calculates the union of multiple maps.

Syntax

map<K, V> map_concat([string <mapDupKeyPolicy>,] map<K, V> <a>, map<K, 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 set odps.sql.map.key.dedup.policy to exception. If you do not specify this parameter, the default value last_win is used.

    Note

    The 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 and b: required. These parameters specify maps. The keys of the maps must be of the same data type, and the values of the maps must be of the same data type. that K and V in map<K, V> specify the keys and values of a map.

Return value

A value of the MAP type is returned. The return value varies based on the following rules:

  • If a map is null or the key of a map is null, null or an error is returned.

  • If the data types of multiple maps are different, an error is returned.

Examples

-- The return value is {1:a, 2:b, 3:c}. 
select map_concat(map(1, 'a', 2, 'b'), map(3, 'c'));
-- The return value is {1:a, 2:d, 3:c}. 
select map_concat('last_win', map(1, 'a', 2, 'b'), map(3, 'c'), map(2, 'd'));

Related functions

MAP_CONCAT 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.