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;
hostodo怎么样?快到了7月4日美国独立日,hostodo现在推出了VPS大促销活动,提供4款Hostodo美国独立日活动便宜VPS,相当于7折,低至$13/年,续费同价。Hostodo美国独立日活动结束时间不定,活动机售完即止。Hostodo商家支持加密数字货币、信用卡、PayPal、支付宝、银联等付款。Hostodo美国独立日活动VPS基于KVM虚拟,NVMe阵列,1Gbps带宽,自带一个...
官方网站:https://www.akkocloud.com/AkkoCloud新品英国伦敦CN2 GIA已上线三网回程CN2 GIA 国内速度优秀.电信去程CN2 GIALooking Glass:http://lonlg.akkocloud.com/Speedtest:http://lonlg.akkocloud.com/speedtest/新品上线刚好碰上国庆节 特此放上国庆专属九折循环优惠...
近日华纳云商家正式上线了美国服务器产品,这次美国机房上线的产品包括美国云服务器、美国独立服务器、美国高防御服务器以及美国高防云服务器等产品,新产品上线华纳云推出了史上优惠力度最高的特价优惠活动,美国云服务器低至3折,1核心1G内存5Mbps带宽低至24元/月,20G ddos高防御服务器低至688元/月,年付周期再送2个月、两年送4个月、三年送6个月,终身续费同价,有需要的朋友可以关注一下。华纳云...