36-综合案例开发-2
1.ETL数据清洗
ETL需求需求1:对字段为空的不合法数据进行过滤where 过滤需求2:通过时间分析得到天和小时字段sbustr函数需求3:GPS经纬度中提取经度和纬度split函数
需求4:将ETL以后的新表保存到一张新的Hive表中
create table … as select …
简称 ctas大法
2. 解题技巧
2.1. 正确解读业务需求,避免歧义
2. 2 确定待查询的数据表 -->from 表
2.3 找出分析维度 ---> group by分组字段
2.4 找出计算的指标 --》聚合的字段
2.5 其他的细节点 (过滤、排序、二次筛查)表: t_user (id,name,age,sex,city)
需求:统计一下每个城市男女人数和男女的平均年龄
分组字段是什么?每个城市、男女聚合字段是什么?
count()
avg(age)
3.案例分析与实现-1
--------------5、需求指标统计分析---------------------2.1. 正确解读业务需求,避免歧义--2. 2 确定待查询的数据表 -->from 表--2.3 找出分析维度 ---> group by分组字段--2.4 找出计算的指标 --》聚合的字段--2.5 其他的细节点 (过滤、排序、二次筛查)--5.1需求:统计今日总消息量 [ 0:00:00 -- 23:59:59分之间的数据]
-- 假设是一个月的数据
-- 使用ctas大法 resultset==rs
create table if not exists tb_rs_total_msg_cnt
comment "今日消息总数"
asselectdayinfo,count(*) as total_msg_cntfrom db_msg_etl
group by dayinfo;-- 结果确认
select * from tb_rs_total_msg_cnt;--5.2需求:统计今日每小时消息量、发送和接收用户数create table if not exists tb_rs_hour_msg_cnt
comment "每小时消息的趋势"
asselectdayinfo,hourinfo,count(*) as total_msg_cnt,count(distinct sender_account) as sender_usr_cnt,count(distinct receiver_account) as receiver_usr_cntfrom db_msg_etl
group by dayinfo, hourinfo;-- 结果检验
select * from tb_rs_hour_msg_cnt;--5.3需求:统计今日各地区发送消息数据量create table if not exists tb_rs_loc_cnt
comment "今日各个地区发送消息总量"
asselectdayinfo,sender_gps,cast(sender_lng as double) as longitude,-- 经度cast(sender_lat as double) as latitude, -- 纬度count(*) as total_msg_cntfrom db_msg_etl
group by dayinfo, sender_gps, sender_lng, sender_lat;-- 校验一下
select * from tb_rs_loc_cnt;select * from tb_msg_source limit 3;select * from db_msg_etl limit 3;select * from db_msg_etl
group by sender_gps,sender_lng,sender_lat;
-- gps (123.257181,48.807394)
-- 经度 123.257181
--纬度 48.807394--5.4需求:统计今日发送消息和接收消息的用户数create table if not exists tb_rs_usr_cnt
asselectdayinfo,count(distinct sender_account) as sender_usr_cnt,count(distinct receiver_account) as receiver_usr_cntfrom db_msg_etl
group by dayinfo;-- 检验数据select * from tb_rs_usr_cnt;