All Products
Search
Document Center

MaxCompute:MAP_KEYS

Last Updated:Jul 24, 2023

Returns all keys in Map a as an array.

Syntax

array<K> map_keys(map<K, V> <a>)

Parameters

a: required. This parameter specifies a map. K and V in map<K, V> specify the keys and values of a map.

Return value

A value of the ARRAY type is returned. If the input map is null, null is returned.

Examples

Return all keys in a map based on the data in the t_table_map table that contains the c1 (BIGINT) and t_map (MAP<STRING,BIGINT>) columns. Data in the table:

+------------+-------+
| c1         | t_map |
+------------+-------+
| 1000       | {k11:86, k21:15} |
| 1001       | {k12:97, k22:2} |
| 1002       | {k13:99, k23:1} |
+------------+-------+

Sample statement:

-- Return keys in the t_map column as an array. 
select c1, map_keys(t_map) from t_table_map;
-- The following result is returned: 
+------------+------+
| c1         | _c1  |
+------------+------+
| 1000       | [k11, k21] |
| 1001       | [k12, k22] |
| 1002       | [k13, k23] |
+------------+------+

Related functions

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