当前位置:   article > 正文

hive的collect_set函数_hive collectset

hive collectset
imeiapp_idapp_typethird_app_typeis_hiadis_iaprow_num
i1a游戏动作射击011
i1b应用阅读113
i1c游戏null005
2a应用阅读101
i2b游戏动作射击112
i2c游戏阅读006

 

  1. create external table pinko.app_info
  2. (
  3. imei string
  4. ,app_id string
  5. ,app_type string
  6. ,third_app_type string
  7. ,is_hiad int
  8. ,is_iap int
  9. ,row_num int
  10. )
  11. row format delimited
  12. fields terminated by '\t'
  13. stored as textfile
  14. location '/warehouse/pinko/app_info'
  15. ;
  1. select
  2. imei
  3. ,concat_ws(',',collect_set(app_id) over(partition by imei order by row_num) ) as app_id_list
  4. ,concat_ws(',',collect_set(app_type) over(partition by imei order by row_num) ) as app_id_list
  5. ,concat_ws(',',collect_set(third_app_type) over(partition by imei order by row_num) ) as app_id_list
  6. ,concat_ws(',',collect_set(if(is_hiad=1,app_id,null)) over(partition by imei order by row_num) ) as hiad_app_id_list
  7. ,concat_ws(',',collect_set(if(is_hiad=1,app_type,null)) over(partition by imei order by row_num) ) as hiad_app_id_list
  8. ,concat_ws(',',collect_set(if(is_hiad=1,third_app_type,null)) over(partition by imei order by row_num) ) as hiad_app_id_list
  9. ,row_num
  10. from app_info

 

  1. select
  2. imei
  3. ,app_id_list
  4. ,app_type_list
  5. ,third_app_id_list
  6. ,hiad_app_id_list
  7. , hiad_app_type_list
  8. , hiad_third_app_id_list
  9. from
  10. (
  11. select
  12. imei
  13. ,concat_ws(',',collect_set(app_id) over(partition by imei order by row_num) ) as app_id_list
  14. ,concat_ws(',',collect_set(app_type) over(partition by imei order by row_num) ) as app_type_list
  15. ,concat_ws(',',collect_set(third_app_type) over(partition by imei order by row_num) ) as third_app_id_list
  16. ,concat_ws(',',collect_set(if(is_hiad=1,app_id,null)) over(partition by imei order by row_num) ) as hiad_app_id_list
  17. ,concat_ws(',',collect_set(if(is_hiad=1,app_type,null)) over(partition by imei order by row_num) ) as hiad_app_type_list
  18. ,concat_ws(',',collect_set(if(is_hiad=1,third_app_type,null)) over(partition by imei order by row_num) ) as hiad_third_app_id_list
  19. ,row_number() over(partition by imei order by row_num desc) as row_num
  20. from app_info
  21. ) t1
  22. where row_num=1

  1. select
  2. imei
  3. ,concat_ws(',',collect_set(app_id) ) as app_id_list
  4. ,concat_ws(',',collect_set(app_type) ) as app_type_list
  5. ,concat_ws(',',collect_set(third_app_type) ) as third_app_id_list
  6. ,concat_ws(',',collect_set(if(is_hiad=1,app_id,null)) ) as hiad_app_id_list
  7. ,concat_ws(',',collect_set(if(is_hiad=1,app_type,null)) ) as hiad_app_type_list
  8. ,concat_ws(',',collect_set(if(is_hiad=1,third_app_type,null)) ) as hiad_third_app_id_list
  9. from app_info
  10. group by imei

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/653978
推荐阅读
相关标签
  

闽ICP备14008679号