str_to_map
function
Applies to: Databricks SQL Databricks Runtime
Creates a map after splitting the input into key-value pairs using delimiters.
Syntax
str_to_map(expr [, pairDelim [, keyValueDelim] ] )
Arguments
expr
: AnSTRING
expression.pairDelim
: An optionalSTRING
literal defaulting to','
that specifies how to split entries.keyValueDelim
: An optionalSTRING
literal defaulting to':'
that specifies how to split each key-value pair.
Returns
A MAP
of STRING
for both keys and values.
Both pairDelim
and keyValueDelim
are treated as regular expressions.
Examples
> SELECT str_to_map('a:1,b:2,c:3', ',', ':');
{a -> 1, b -> 2, c -> 3}
> SELECT str_to_map('a');
{a-> NULL}
> SELECT str_to_map('5A10B6A20' COLLATE UTF8_BINARY, 'b', 'a');
{5A10B6A20 -> NULL}
> SELECT str_to_map('5A10B6A20' COLLATE UTF8_LCASE, 'b', 'a');
{5 -> 10, 6 -> 20}