Applies a lambda expression to every entry in a map and constructs a new map with the original keys and the transformed values. The lambda receives the key and value of each entry.
TRANSFORM_VALUES((<key>, <value>) -> <new_value>, <map>)
| Parameter | Description |
|---|---|
<key> | The lambda parameter representing the key of a map entry. |
<value> | The lambda parameter representing the value of a map entry. |
<new_value> | An expression that produces the value in the returned map. |
<map> | A MAP<K, V> expression. |
Returns a MAP<K, V2>, where V2 is the type returned by the lambda.
<map> is empty, returns an empty map.<map> is NULL, returns NULL.NULL value returned by the lambda is retained.SELECT transform_values((k, v) -> v + k, map(1, 10, 2, 20)) AS result;
+--------------+ | result | +--------------+ | {1:11, 2:22} | +--------------+
SELECT transform_values( (k, v) -> if(k = 1, CAST(NULL AS INT), v), map(1, 10, 2, 20)) AS result;
+----------------+ | result | +----------------+ | {1:null, 2:20} | +----------------+
SELECT transform_values((k, v) -> v, CAST(NULL AS MAP<INT, INT>)) AS result;
+--------+ | result | +--------+ | NULL | +--------+