Tuesday, 10 September 2019

Converting string to map data type in Hive

Converting string to map data type in Hive



If  you have a string with key value pairs and want to convert to a map data type with key value pairs then use the str_to_map function.


str_to_map(text, delimiter1, delimiter2) - Creates a map by parsing text Split text into key-value pairs using two delimiters. The first delimiter seperates pairs, and the second delimiter sperates key and value. If only one parameter is given, default delimiters are used: ',' as delimiter1 and '=' as delimiter2.

Example:

with t1 as (
select "k1:v1|k2:v2|k3:v3" as c1
 )


select str_to_map(c1 ,"\\|",":") as m1, c1 from t1



No comments:

Post a Comment