hive 的数据案例 统计网站的数据信息


  • 根据hive的案例一增加需求

一: 增加案例需求:

统计 pv , uv , 登录人数 , 游客人数 , 平均访问时长 , 二跳率 , 独立IP 
用一张表去处理

1.1 查看track_log的分区

show partitions track_log ;

image_1akacgkv21q8015ugmrq1l1fpea9.png-7.2kB

1.2 建立一张会话信息表(session):

create table session_info(
session_id string,
guid string,
trackerU string,
landing_url string,
landing_url_ref string,
user_id string,
pv string,
stay_time string,
min_trackTime string,
ip string,
provinceId string
)
partitioned by (date string)
row format delimited fields terminated by '\t' ;

image_1akaflsmn1pca1ll4kcu107hp021g.png-23.6kB

1.3 创建临时表 session_info_tmp1

create table session_info_tmp1 as select 
sessionId session_id,
max(guid) guid,
--trackerU string,
--landing_url string,
--landing_url_ref string,
max(endUserId) user_id,
count(url) pv,
(max(unix_timestamp(trackTime)) - min(unix_timestamp(trackTime)))  stay_time,
min(trackTime) min_trackTime ,
max(ip) ip,
max(provinceId) provinceId
from track_log where date='20150828'
group by sessionId ;

image_1akafgfel12phthja53a4f14kvm.png-36.6kB

1.4 创建临时表session_info_tmp2

create table session_info_tmp2 as select
sessionId session_id,
trackTime trackTime,
trackeru trackerU,
url landing_url,
referer landing_url_ref
from track_log where date='20150828' ;

image_1akafk8g1tpr18ap4bp1h32cn913.png-60.8kB

1.5 导入数据处理:

insert overwrite table session_info partition (date='20150828')
select
a.session_id,
a.guid,
b.trackerU,
b.landing_url,
b.landing_url_ref,
a.user_id,
a.pv,
a.stay_time,
a.min_trackTime,
a.ip,
a.provinceId
from session_info_tmp1 a  join session_info_tmp2 b
on a.session_id=b.session_id 
and a.min_trackTime=b.trackTime ;

image_1akafs6ipugb1p5o1vogvhpnoo1t.png-46.3kB

1.6 生成最后所需的表:

create table vistor_users_info as
select
date,
count(distinct guid) UV,
sum(pv) PV,
count(case when user_id != '' then user_id else null end) login_users,
count(case when user_id = '' then user_id else null end) vistor_users,
avg(stay_time) avg_stay_time,
count(case when pv>=2 then session_id else null end)/count(session_id) sec_ratio,
count(distinct ip) ip
from session_info where date='20150828'
group by date ;

image_1akag6l92upa17uf1ba11aii4ak2a.png-41.3kB

1.7 查询结果:

select * from vistor_users_info;

image_1akag8pme1dspe58uli1ejvh602n.png-19.8kB

转载于:https://blog.51cto.com/flyfish225/2097296

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值