hive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bejoy Ks <>
Subject Re: hive map field question
Date Wed, 23 Nov 2011 18:04:50 GMT
Hi Chalcy
        Support for splitting a column of map data type into key and values is available
on the hive latest trunk. You can use a explode() UDF to achieve the same, which used to support
only arrays previously.

You need to patch your hive source installation to get this functionality running. Or as a
quick fix (not highly recommended) take the source code include the same as a Custom UDF for
your temporary usage. You can utilize the explode functionality as follows combining the same
with Lateral Views.
Sample DDL
  clmn1 STRING,
  clmn2 STRING,

Sample DML - to extraxt key values from map
SELECT clmn1,clmn2,clmnMap_key,clmnMap_value FROM test_map 
LATERAL VIEW explode(clmnMap) cl AS clmnMap_key,clmnMap_value;

Hope it helps!...


 From: Mark Grover <>
Sent: Wednesday, November 23, 2011 9:55 PM
Subject: Re: hive map field question
I don't know of an existing UDF that lists all keys and values of a map. You may want to check
ql/src/java/org/apache/hadoop/hive/ql/udf in Hive source to double check.
But, as you might have guessed, it'd be pretty straightforward to do that in your own UDF:-)


----- Original Message -----
From: "Chalcy Raja" <>
To: "" <>
Sent: Wednesday, November 23, 2011 11:14:09 AM
Subject: RE: hive map field question

Thanks, Mark.  I'll try that.  

Also, is there a way to list all the keys and values in a map field?


-----Original Message-----
From: Mark Grover [] 
Sent: Wednesday, November 23, 2011 11:01 AM
Subject: Re: hive map field question

Hi Chalcy,
You could write a UDF that takes in a Map object and returns you the string you need.

Alternatively, you could use Hive Transform. Details here:

When a map gets passed to your custom transform script, you could read it as a serialized


----- Original Message -----
From: "Chalcy Raja" <>
Sent: Wednesday, November 23, 2011 10:48:07 AM
Subject: hive map field question

Hello HiveUsers, 

I have a need to convert a map<string,string> field to string field and vice versa in
a hive table. I could not do cast. 

I created two external tables with one has string and another map. I can join both to get
what I want, takes a long time. 

Any ideas of how it can be done efficiently ? 


View raw message