Spark SQL - Convert Delimited String to Map using str_to_map Function

visibility 257 event 2022-06-04 access_time 7 months ago language English
more_vert

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.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts