str_to_map function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Creates a map after splitting the input into key-value pairs using delimiters.

Syntax

str_to_map(expr [, pairDelim [, keyValueDelim] ] )

Arguments

  • expr: An STRING expression.
  • pairDelim: An optional STRING literal defaulting to ',' that specifies how to split entries.
  • keyValueDelim: An optional STRING 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}