当前位置:   article > 正文

Hive,FineBI-30W聊天数据分析及可视化-B站黑马学习记录_基于 hive 的数据分析案例-mm 聊天软 件数据分析

基于 hive 的数据分析案例-mm 聊天软 件数据分析

2023B站黑马Hadoop、Hive、云平台实战项目

目录

1. 清洗数据

2. 计算各指标,并创建表存储结果

3.FineBI连接Hive数据库,将指标结果可视化


1. 清洗数据

1)部分数据缺失地理位置信息(sender_gps),需要剔除

  1. select count(if(length(sender_gps)=0,1,null)) count_null_sender_gps,
  2. count(if(length(receiver_gps)=0,1,null)) count_null_receiver_gps
  3. from tb_msg_source;

2)为方便处理,从时间中提取天、小时字段,GPS中提取经度、纬度

创建etl表,存储清洗后的数据

  1. insert overwrite table tb_msg_etl30
  2. select *, date(msg_time) msg_day,
  3. hour(msg_time) msg_hour,
  4. split(sender_gps,',')[0] sender_lng,
  5. split(sender_gps,',')[1] sender_lat
  6. from tb_msg_source30
  7. where length(sender_gps)>0;

2. 计算各指标,并创建表存储结果

  1. -- 统计今日消息总量
  2. create table tb_rs_total_msg_cnt comment '每日消息总量' as
  3. select msg_day, count(*) total_msg_cnt from tb_msg_etl30 group by msg_day;
  4. -- 统计每小时消息量、发送和接收用户数
  5. create table tb_rs_hour_msg_cnt comment '每小时消息趋势' as
  6. select msg_hour, count(*) total_msg_cnt, count(distinct sender_account) sender_user_cnt,
  7. count(distinct receiver_account) receiver_user_cnt
  8. from tb_msg_etl30 group by msg_hour;
  9. -- 统计今日各地区发送消息总量
  10. create table tb_rs_loc_cnt comment '今日各地区发送消息总量' as
  11. select msg_day, sender_lng, sender_lat, count(*) total_msg_cnt
  12. from tb_msg_etl30
  13. group by msg_day, sender_lng, sender_lat;
  14. -- 统计今日发送和接收用户数
  15. create table tb_rs_user_cnt comment '每日发送和接收消息的人数' as
  16. select msg_day, count(distinct sender_account) sender_user_cnt,
  17. count(distinct receiver_account) receiver_user_cnt
  18. from tb_msg_etl30
  19. group by msg_day;
  20. -- 统计发送消息条数最多的前十个用户
  21. create table tb_rs_s_user_top10 comment '发送消息最多的10个用户' as
  22. select sender_name, count(*) sender_msg_cnt
  23. from tb_msg_etl30
  24. group by sender_name
  25. order by sender_msg_cnt desc
  26. limit 10;
  27. -- 统计接收消息条数最多的前十个用户
  28. create table tb_rs_r_user_top10 comment '接收消息最多的10个用户' as
  29. select receiver_name, count(*) receiver_msg_cnt
  30. from tb_msg_etl30
  31. group by receiver_name
  32. order by receiver_msg_cnt desc
  33. limit 10;
  34. -- 统计发送人的手机型号分布情况
  35. create table tb_rs_sender_phone comment '发送人的手机型号分布' as
  36. select sender_phonetype, count(*) cnt
  37. from tb_msg_etl30
  38. group by sender_phonetype;
  39. -- 统计发送人的手机操作系统分布
  40. create table tb_rs_sender_os comment '发送人的手机操作系统分布' as
  41. select sender_os, count(*) cnt
  42. from tb_msg_etl30
  43. group by sender_os;

1)统计今日消息总量

2)统计每小时消息量、发送和接收用户数

3)统计今日各地区发送消息总量

注:模拟数据中只有100个不同用户,实际中按经纬度坐标group by太细了,应该换算出地区

4)统计今日发送和接收用户数

5)统计发送消息条数最多的前十个用户

6)统计接收消息条数最多的前十个用户

7)统计发送人的手机型号分布情况

8)统计发送人的手机操作系统分布

3.FineBI连接Hive数据库,将指标结果可视化

 记:在阿里云上搭建了3台虚拟机Hadoop集群,最开始觉得性能应该够用,想跑1000W数据,结果计算创建etl表的时候,用了快2小时都没跑出来。后面换成30W数据,同一条sql语句花了2秒多。

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

闽ICP备14008679号