MAP_UNION

Updated at:

Returns a new map that is the union of all input maps. If a key exists in multiple input maps, one of the values that correspond to the key is randomly retained.

Usage notes

  • MaxCompute V2.0 provides new extended functions. If the functions you use involve new data types, including TINYINT, SMALLINT, INT, FLOAT, VARCHAR, TIMESTAMP, and BINARY, you must execute a statement to enable the MaxCompute V2.0 data type edition:

    • Session level: Add SET odps.sql.type.system.odps2=true; before the SQL statement that you want to execute, and commit and execute them together.

    • Project level: The project owner can enable the MaxCompute V2.0 data type edition for the project based on the project requirements. Statement:

      setproject odps.sql.type.system.odps2=true;

      The configuration takes effect after 10 to 15 minutes.

      For more information about setproject, see Project commands. For more information about the precautions you must take when enabling the MaxCompute V2.0 data type edition at the project level, see Data type version guide.

  • If you use an SQL statement that includes multiple aggregate functions and the project resources are insufficient, memory overflow may occur. We recommend that you optimize the SQL statement or purchase additional computing resources as needed.

Syntax

map<K, V> map_union(map<K, V> input);

Parameters

input: the input maps.

Return value

A new map that is the union of all input maps is returned.

Examples

select map_union(a) from values
    (map(1L, 'hi', 2L, 'apple', 3L, 'pie')), (map(1L, 'good', 4L, 'this')), (null) t(a);

The following result is returned:

+-----------------------------------------------+
| _c0                                           |
+-----------------------------------------------+
| {"4":"this","1":"good","2":"apple","3":"pie"} |
+-----------------------------------------------+

Related functions

MAP_UNION is an aggregate function. For more information about the functions that are used to calculate the average value of multiple input records and to aggregate parameters, see Aggregate Functions Overview.