Hive Explode / Lateral View multiple arrays

后端 未结 5 946
刺人心
刺人心 2020-11-30 02:23

I have a hive table with the following schema:

COOKIE  | PRODUCT_ID | CAT_ID |    QTY    
1234123   [1,2,3]    [r,t,null]  [2,1,null]

How

5条回答
  •  一个人的身影
    2020-11-30 02:54

    I tried to work out on your scenario... please try this code -

    create table info(cookie string,productid int,catid string,qty string);
    
    insert into table info
    select cookie,productid[myprod],categoryid[mycat],qty[myqty] from table
    lateral view posexplode(productid) pro as myprod,pro
    lateral view posexplode(categoryid) cate as mycat,cate
    lateral view posexplode(qty) q as myqty,q
    where myprod=mycat and mycat=myqty;
    

    Note - In the above statements, if you place - select cookie,myprod,mycat,myqty from table in place of select cookie,productid[myprod],categoryid[mycat],qty[myqty] from table in the output you will get the index of the element in the array of productid, categoryid and qty. Hope this will be helpful.

提交回复
热议问题