代码之家  ›  专栏  ›  技术社区  ›  DevEx

如何在蜂窝中分解地图阵列

  •  0
  • DevEx  · 技术社区  · 6 年前

    考虑一张桌子 my_table 具有以下结构:

    >> describe my_table
    
    id               bigint
    info_detail      map<bigint,array<string>>
    

    如果我爆炸 info_detail ,最后是数组:

    >> select explode(info_detail) as (info_id, detail) 
       from my_table
    
       info_id  detail
       112344   ["something about 112344", "other things"]
       342302   ["something about 342302"]
    

    如何爆炸 detail 同样,结果是这样的:

       info_id  detail
       112344   "something about 112344"
       112344   "other things"
       342302   "something about 342302"
    
    2 回复  |  直到 6 年前
        1
  •  1
  •   hlagos    6 年前

    select info_id, d from (
    select explode(info_detail) as (info_id, detail) 
    from my_table
    ) t lateral view explode(detail) detailexploded as d;
    
        2
  •  -1
  •   Vamsi Prabhala    6 年前

    explode map array

    select tbl.info_id,tbl1.details
    from my_table m
    lateral view explode(info_detail) tbl as info_id,detail 
    lateral view explode(detail) tbl1 as details