I found an UDAF from the facebook libraries (
https://issues.apache.org/jira/browse/HIVE-1545) called collect_map which
seems to serve the purpose.

Still if this could be done natively by Hive, then it would be good.Any
ideas ?


On Thu, Oct 18, 2012 at 5:42 PM, Himanish Kushary <himan...@gmail.com>wrote:

> Hi,
>
> I have a table (Table A) with the following data :
>
> name    pid    pflag    pstr  count
> ========================
> ABC    502 01 0000   1
> ABC    502 01 0010   2
> ABC    502 01 0020   2
> DEF    504 01 0101   1
> GHI    502 00 0000   1
>
> I want to put this data into another table(Table B) so that the data looks
> like :
>
> name  pid   pflag    pstrcount
> ==================================
> ABC   502   01     {"0000":1;"0010":2;"0020":2}
> DEF   504   01     {"0101":1}
> GHI   502   00       {"0000":1}
>
> So pstrcount column is a map of the pstr and count from the Table A.
>
> Do I need to write custom UDAF to get this done or is there any way
> to achieve this out of the box using some Hive function/construct etc.
>
> I tried this query :
>
> create table B stored as sequencefile
> as
> select name,pid,pflag,map(pstr,count) as pstrcount from A;
>
> but got this output :
>
> ABC 502 01 {"0000":1}
> ABC 502 01 {"0010":2}
> ABC 502 01 {"0020":2}
> DEF 504 01 {"0101":1}
> GHI 502 00 {"0000":1}
>
> Could somebody please help.
>
> --
> Thanks & Regards
> Himanish
>



-- 
Thanks & Regards
Himanish

Reply via email to