Skip to content

Instantly share code, notes, and snippets.

@developer-sdk
Created April 5, 2017 14:56
Show Gist options
  • Select an option

  • Save developer-sdk/044284199311e58ee79316cd87f42f35 to your computer and use it in GitHub Desktop.

Select an option

Save developer-sdk/044284199311e58ee79316cd87f42f35 to your computer and use it in GitHub Desktop.
hive: str_to_map()
-- STR_TO_MAP 사용법
SELECT STR_TO_MAP("key1: value1, key2: value2, key3: value3", list_delimiter, key_value_delimiter);
-- example #1
hive> SELECT STR_TO_MAP("key1: value1, key2: value2, key3: value3", ",", ":");
OK
{"key1":" value1"," key3":" value3"," key2":" value2"}
Time taken: 0.049 seconds, Fetched: 1 row(s)
-- json string to map
hive> SELECT STR_TO_MAP(REPLACE(
> REPLACE(
> REPLACE(
> REPLACE('{ "name": "json", "class": "math", "age": 15 }', '{', '')
> , '}', '')
> , '"', ''), ' ', '')
> , ",", ":")
> ;
OK
{"name":"json","class":"math","age":"15"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment