1.数据处理
扩展脚本 年月日vim log-extend.sh
[root@master~]#bash log-extend.sh sogou.500w.utf8 sogou_log.txt过滤脚本过滤搜索为空
Vim log-fi lter.sh
[root@master~]#bash log-fi lter.sh sogou_log.txt sogou_log.txt.flt
1.上传文件到h d fs
基于HIve构建日志数据的数据仓库
创建数据库hive>create database sogou;
使用数据库
Hive>use sogou;
创建扩展4个字段年、月、 日、小时数据的外部表hive>CREATE EXTERNALTABLE sogou_data(ts string,uid string,keyword string,rankint,sorder int,url string,year int,month int,dayint,hour int)
>ROWFORMATDELIMITED
>FIELDSTERMINATED BY'\t'
>STORED ASTEXTFILE;
OK
Timetaken:0.412seconds
Hive表加载数据load data inpath'/home/sogou_log.txt.flt' intotable sogou_data;
创建带分区的表hive>CREATE EXTERNALTABLE sogou_partitioned_data(ts string,uid string,keyword stringrankint,sorder int,url string)
>PARTITIONED BY(year int,monthint,dayint,hour int)>ROWFORMATDELIMITED
>FIELDSTERMINATED BY'\t'
>STORED ASTEXTFILE;
设置动态分区hive>set hive.exec.dynamic.partition.mode=nonstrict;hive> INSERT OVERWRITE TABLE sogou_partitioned_data partition(year,month,day,hour)SELECT* FROM sogou_data;
查询测试
Hive>select *from sogou_data l imit 10;
hive>select *from sogou_data l imit 10;
hive>select*from sogou_data where uid='6961d0c97fe93701fc9c0d861d096cd9';
(1)查询总条数hive>select count(*) from sogou_partitioned_data;
OK
5000000
(2)非空查询条数hive>select count(*) from sogou_partitioned_data where keyword is not nul l and keyword!=' ';
5000000
Time taken:28.606 seconds, Fetched: 1 row(s)
(3)无重复总条数hive> select count(*) from(select count(*) as no_repeat_count from sogou_partitioned_datagroup byts,uid,keyword,url having no_repeat_count=1)a;
OK
4999272
Time taken: 101.228 seconds, Fetched: 1 row(s)
(4)独立UID总数hive>select count(distinct(uid)) from sogou_partitioned_data;
OK
1352664
Time taken:44.639 seconds, Fetched: 1 row(s)
实现数据分析需求二关键字分析
(1)查询频度排名频度最高的前50词hive> select keyword,count(*)query_count from sogou_partitioned_data group by keywordorderby query_countdesc l imit50;
Total MapReduceCPUTimeSpent: 1 minutes4seconds510msec
OK
百度 38441baidu 18312
人体艺术 14475
4399小游戏 11438qq空间 10317
优酷 10158
新亮剑 9654
馆陶县县长闫宁的父亲 9127
公安卖萌 8192
百度一下你就知道7505
百度一下 7104
4399 7041
魏特琳 6665qq网名 6149
7k7k小游戏 5985
黑狐 5610
儿子与母亲不正当关系 5496
新浪微博 5369
李宇春体 5310
新疆暴徒被击毙图片 4997hao123 4834
123 4829
4399洛克王国 4112qq头像 4085nba 4027
龙门飞甲 3917qq个性签名 3880
张去死 3848cf官网3729
凰图腾 3632
快播 3423
金陵十三钗 3349
吞噬星空 3330dnf官网 3303
武动乾坤 3232
新亮剑全集 3210
电影 3155
优酷网 3115
两次才处决美女罪犯 3106
电影天堂 3028
土豆网 2969qq分组 2940
全国各省最低工资标准 2872
清代姚明 2784youku 2783
争产案 2755dnf 2686
12306 2682
身份证号码大全 2680
火影忍者 2604
Time taken: 119.195 seconds, Fetched:50 row(s)
实现数据分析需求三 UID分析
(1)查询次数大于2次的用户总数hive> select count(*) from(select count(*) as query_count from sogou_partitioned_datagroupby uid having query_count>2)a;
OK
546353
Timetaken:69.837 seconds, Fetched: 1 row(s)
(2)查询次数大于2次的用户占比
A:hive> select count(*) from(select count(*) as query_count from sogou_partitioned_datagroupby uid having query_count>2)a;
OK
546353
Timetaken:69.837 seconds, Fetched: 1 row(s)
Bhive>select count(distinct(uid)) from sogou_partitioned_data;
OK
1352664
A/Bhive>select 546353/1352664;
OK
0.40390887907122536
Timetaken:0.255 seconds, Fetched: 1 row(s)
(3) rank次数在10以内的点击次数占比rank既是第四列的内容
A:
hive>select count(*) from sogou_partitioned_data where rank<11;
4999869
Time taken:29.653 seconds, Fetched: 1 row(s)
B:hive>select count(*) from sogou_partitioned_data;
5000000
A/Bhive>select 4999869/5000000;
OK
0.9999738
(4)直接输入URL查询的比例
A:hive>select count(*) from sogou_partitioned_data where keyword l ike '%www%';
OK
73979
B:hive>select count(*) from sogou_partitioned_data;
OK
5000000
A/Bhive>select 73979/5000000;
OK
0.0147958
实现数据分析需求四独立用户行为分析
(1)查询搜索过”仙剑奇侠传“的uid并且次数大于3hive> select uid,count(*) as cnt from sogou_partitioned_data where keyword='仙剑奇侠传'groupby uid havingcnt>3;
ProfitServer已开启了黑色星期五的促销活动,一直到本月底,商家新加坡、荷兰、德国和西班牙机房VPS直接5折,无码直购最低每月2.88美元起,不限制流量,提供IPv4+IPv6。这是一家始于2003年的俄罗斯主机商,提供虚拟主机、VPS、独立服务器、SSL证书、域名等产品,可选数据中心包括俄罗斯、法国、荷兰、美国、新加坡、拉脱维亚、捷克、保加利亚等多个国家和地区。我们随便以一个数据中心为例...
Sharktech又称SK或者鲨鱼机房,是一家主打高防产品的国外商家,成立于2003年,提供的产品包括独立服务器租用、VPS云服务器等,自营机房在美国洛杉矶、丹佛、芝加哥和荷兰阿姆斯特丹等。之前我们经常分享商家提供的独立服务器产品,近期主机商针对云虚拟服务器(CVS)提供优惠码,优惠后XS套餐年付最低仅33.39美元起,支持使用支付宝、PayPal、信用卡等付款方式。下面以XS套餐为例,分享产品配...
RAKsmart怎么样?RAKsmart是一家由华人运营的国外主机商,提供的产品包括独立服务器租用和VPS等,可选数据中心包括美国加州圣何塞、洛杉矶、中国香港、韩国、日本、荷兰等国家和地区数据中心(部分自营),支持使用PayPal、支付宝等付款方式,网站可选中文网页,提供中文客服支持。本月商家继续提供每日限量秒杀服务器月付30.62美元起,除了常规服务器外,商家美国/韩国/日本站群服务器、1-10...