hive array struct转string

本文共有890个字,关键词:

问题:hive的字段是array<struct>类型,如何将数据转换成字符串?

解决:一步步拆解

方法:
hive字段

`page_stats` ARRAY<STRUCT<page_id:STRING,page_count:BIGINT,during_time:BIGINT>> COMMENT '页面访问统计'

数据生成方法

select
    mid_id,
    collect_set(named_struct('page_id',page_id,'page_count',page_count,'during_time',during_time)) page_stats
from
(
    select
        mid_id,
        page_id,
        count(*) page_count,
        sum(during_time) during_time
    from dwd_page_log
    where dt='2020-06-14'
    group by mid_id,page_id
)t2
group by mid_id

拆解

concat_ws(explore)
select 
    tmp.custom_id,
    c1.jijin
from test_youhua.test_array_struct_inline as tmp lateral view explode(tmp.all_bal) t1 as c1; 

参考:

https://www.cnblogs.com/foolangirl/p/14326886.html
版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。
添加新评论
暂无评论