zoukankan      html  css  js  c++  java
  • 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返回重复的集合

    另外concat_ws也可以不在group by中使用,比如:

    select concat_ws(',', 'a', 'b', 'c') from dual
    # 输出:a,b,c
    
    

    concat是用在非goup by 场景,如:

    select  concat('a', '
    ', 'b', '	', 'c',  ',',  'd'))
    
    #测试
    select 
        --replace(info, '	', '')
        regexp_replace(info, '	', '')
        ,regexp_replace(info, '(	|
    |###|  )', '')
    from(
        select concat('a', '
    ', 'b', '	', 'c', '	', '测试###a    c,华尔街') as info
    )a
    

    参考: https://blog.csdn.net/changzoe/article/details/81181820

  • 相关阅读:
    定位 -CLGeocoder
    定位
    定位
    定位- 汽车导航
    定位
    SVN
    githubRepository -- 使用
    git 常用指令
    ipad ------ 与iPhone的差别
    总结
  • 原文地址:https://www.cnblogs.com/ying-chease/p/15399053.html
Copyright © 2011-2022 走看看