2

I am using str_to_map as:-

hive> select str_to_map("A:1,B:1,C:1");
OK
{"C":"1","A":"1","B":"1"}

As you can notice it is returning object of type map < string,string>. I want object of type map. Is there any way out? Can we typecast it in some way to map< string,int>?

0

2 Answers 2

2

I stared at this and looked around for a while and didn't see much, but turns out it's quite simple -- just use cast:

select cast(str_to_map("A:1,B:1,C:1") as map<string, int>)
-- {'A': 1, 'B': 1, 'C': 1}
Sign up to request clarification or add additional context in comments.

3 Comments

fails with syntax error:- FAILED: ParseException line 1:41 cannot recognize input near 'map' '<' 'string' in primitive type specification
Hmm it's working perfectly well for me in Spark SQL which I had assumed is equivalent to HiveQL...
looks like it's not that similar, there might be subtle differences
0

You can try to use map_remove_keys UDF:

> add jar hdfs:///lib/brickhouse-0.7.1-SNAPSHOT.jar;
> create temporary function map_remove_keys as 'brickhouse.udf.collect.MapRemoveKeysUDF';
> select map_remove_keys(map("", 0), array(""));
+------+
| _c0  |
+------+
| {}   |
+------+

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.