目录
1、聊天软件数据分析案例需求
MR速度慢—引入hive
背景:大量的用户在线,通过对聊天数据的分析,构建用户画像,为用户提供更好的服务、以及实现高ROI的平台运营推广,给公司的发展决策提供精确的数据支撑。
目标:基于Hadoop和Hive实现聊天数据统计分析,构建聊天数据分析报表
需求:
- 统计今日总消息量
- 统计今日每小时消息量、发送和接收用户数
- 统计今日各地区发送消息数据量
- 统计今日发送消息和接收消息的用户数
- 统计今日发送消息最多的Top10用户
- 统计今日接收消息最多的Top10用户
- 统计发送人的手机型号分布情况
- 统计发送人的设备操作系统分布情况
原始数据:业务系统中导出的某一天24小时的用户聊天数据,TSV文件。列分隔符:制表符 \t
2、基于Hive数仓实现需求开发
在Notepad中可以通过显示所有字符来判断间隔符
打开Datagrip,创建一个hive工程,语言选择hive,并与hive服务器创建连接。
Datagrip中:
2.1 建库
--------------1、建库-------------------
--如果数据库已存在就删除
drop database if exists db_msg cascade;
--创建数据库
create database db_msg;
--切换数据库
use db_msg;
2.2 建表
--------------2、建表-------------------
--如果表已存在就删除
drop table if exists db_msg.tb_msg_source;
--建表
create table db_msg.tb_msg_source(
msg_time string comment "消息发送时间"
, sender_name string comment "发送人昵称"
, sender_account string comment "发送人账号"
, sender_sex string comment "发送人性别"
, sender_ip string comment "发送人ip地址"
, sender_os string comment "发送人操作系统"
, sender_phonetype string comment "发送人手机型号"
, sender_network string comment "发送人网络类型"
, sender_gps string comment "发送人的GPS定位"
, receiver_name string comment "接收人昵称"
, receiver_ip string comment "接收人IP"
, receiver_account string comment "接收人账号"
, receiver_os string comment "接收人操作系统"
, receiver_phonetype string comment "接收人手机型号"
, receiver_network string comment "接收人网络类型"
, receiver_gps string comment "接收人的GPS定位"
, receiver_sex string comment "接收人性别"