Hive Explode / Lateral View multiple arrays

后端 未结 5 945
刺人心
刺人心 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条回答
  •  旧时难觅i
    2020-11-30 02:53

    You can use the numeric_range and array_index UDFs from Brickhouse ( http://github.com/klout/brickhouse ) to solve this problem. There is an informative blog posting describing in detail over at http://brickhouseconfessions.wordpress.com/2013/03/07/exploding-multiple-arrays-at-the-same-time-with-numeric_range/

    Using those UDFs, the query would be something like

    select cookie,
       array_index( product_id_arr, n ) as product_id,
       array_index( catalog_id_arr, n ) as catalog_id,
       array_index( qty_id_arr, n ) as qty
    from table
    lateral view numeric_range( size( product_id_arr )) n1 as n;
    

提交回复
热议问题