transform_keys
function
Applies to: Databricks SQL Databricks Runtime
Transforms keys in a map in expr
using the function func
.
Syntax
transform_keys(expr, func)
Arguments
expr
: A MAP expression.func
: A lambda function.
Returns
A MAP where the keys have the type of the result of the lambda functions and the values have the type of the expr
MAP values.
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 key for each entry in the map.
Examples
> SELECT transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> k + 1);
{2 -> 1, 3 -> 2, 4 -> 3}
> SELECT transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> k + v);
{2 -> 1, 4 -> 2, 6 -> 3}