Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Hive, mail # user - Any existing UDTF to flatten map


Copy link to this message
-
Re: Any existing UDTF to flatten map
Matt Tucker 2012-11-30, 19:39
I ended up getting an error (Hive 0.7.1), but I would have thought
something like the following would work:

SELECT
    user_id,
    obj_key,
    obj[obj_key] AS obj_item
FROM (
    SELECT
        "user1" user_id,
        MAP("k1", "v1", "k2", "v2") obj
    FROM calendar
    LIMIT 1
) tmp
    LATERAL VIEW EXPLODE(MAP_KEYS(obj)) obj_tbl AS obj_key;

There error that I get for this is: FAILED: Error in semantic analysis:
Line 3:4 Non-constant expression for map indexes not supported obj_key

Matt

On Fri, Nov 30, 2012 at 1:18 PM, xu ji <[EMAIL PROTECTED]> wrote:

> Hi all,
>   I have a table like this:
> hive> desc mytable;
> ts bigint
> content map<string,string>
> hive> select * from mytable;
> 1354299050        {"F1":"id-1"}
> 1354299040        {"F1":"id-2","F2":"id-3"}
> 1354299030        {"F1":"id-3","F2":"id-1","F3":"id-4"}
>
> Does anyone know how to generate a table like this:
>
> hive> desc resulttable;
> id string
> ts bigint
> hive> select * from resulttable;
> id-1        1354299050
> id-2        1354299040
> id-3        1354299040
> id-3        1354299030
> id-1        1354299030
> id-4        1354299030
>
>
> I mean I can certainly write a UDTF to generate a table like this, but I
> wonder is there an existing UDTF to do this job?
>
> Thanks,
> Xu
>
> --
> Ji Xu
> Mobile: (+86) 138-115-10101
> E-mail: [EMAIL PROTECTED]
> Homepage: http://about.me/jixu
>
> Room 825, School of Software,
> Main Building, Tsinghua University,
> Beijing, 100084, P. R. China.
>
>