transform_values
function
Applies to: Databricks SQL Databricks Runtime
Transforms values in a map in expr
using the function func
.
Syntax
transform_values(expr, func)
Arguments
expr
: A MAP expression.func
: A lambda function.
Returns
A MAP where the values have the type of the result of the lambda functions and the keys have the type of the expr
MAP keys.
The lambda function must have 2 parameters. The first parameter represents the key. The second parameter represents the value.
The lambda function produces a new value for each entry in the map.
Examples
> SELECT transform_values(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> v + 1);
{1 -> 2, 2 -> 3, 3 -> 4}
> SELECT transform_values(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> k + v);
{1 -> 2, 2 -> 4, 3 -> 6}