Spark SQL - Convert Delimited String to Map using str_to_map Function
Spark SQL function str_to_map can be used to split the delimited string to key value pairs.
Function syntax
str_to_map(text[, pairDelim[, keyValueDelim]])
The default values for the parameters are:
- pairDelim:
,
- keyValueDelim:
:
Code snippets
The following code snippets convert string to map
object:
spark-sql> select str_to_map('1:a,2:b,3:c,4:d'); str_to_map(1:a,2:b,3:c,4:d, ,, :) {"1":"a","2":"b","3":"c","4":"d"}
copyright
This page is subject to Site terms.
comment Comments
No comments yet.