Kontext Kontext | Code Snippets & Tips

Spark SQL - Convert Delimited String to Map using str_to_map Function

event 2022-06-04 visibility 1,154 comment 0 insights toc
insights Stats
toc Table of contents

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, ,, :)
More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts