其他分享
首页 > 其他分享> > hive的重要操作

hive的重要操作

作者:互联网

1、trans_array实现

       select 
            b1.item_id,
            b2.product_info
        from(
            select 
                product_id as product_list
            from table_1
            where product_id is not null and length(product_id)>1
        )b1
        LATERAL VIEW EXPLODE(split(b1.product_list, '###')) b2 AS product_info      

2、group by 字符串连接操作

select 
        user_id
        ,concat_ws(',', collect_set(leaf_name)) as leaf_names
        ,concat_ws(',', collect_list(leaf_name)) as leaf_names
        ,count(*) as cnt 
from table_1
group by user_id 

主意:collect_set 返回不重复的集合;collect_list返回重复的集合
参考: https://blog.csdn.net/changzoe/article/details/81181820

标签:product,重要,list,hive,collect,leaf,b1,操作,id
来源: https://www.cnblogs.com/ying-chease/p/15399053.html