大数据Hive学习案例(1)——基于搜狗sogou_500w的日志数据分析

下方有数据可免费下载


数据下载 请点击我,提取码:cutx,觉得有用希望您能点一个赞哦。

数据预处理

查看数据

[hadoop@hadoop000 hive_data]$ less sogou.500w.utf8
20111230000005  57375476989eea12893c0c3811607bcf        奇艺高清        1       1       http://www.qiyi.com/
20111230000005  66c5bb7774e31d0a22278249b26bc83a        凡人修仙传      3       1       http://www.booksky.org/BookDetail.aspx?BookID=1050804&Level=1
20111230000007  b97920521c78de70ac38e3713f524b50        本本联盟        1       1       http://www.bblianmeng.com/

[hadoop@hadoop000 hive_data]$ wc -l sogou.500w.utf8
5000000 sogou.500w.utf8

数据扩展

主要目的:将第一列的‘时间’进行substr操作,分成年,月,日,时这四列,加到数据的后面,方便后面进行分区。

[hadoop@hadoop000 hive_data]$ vi sogou-log-extend.sh
#!/bin/bash
#infile=/sogou_500w.utf8
infile=$1
#outfile=/sogou_500w.utf8.ext
outfile=$2
awk -F '\t' '{print $0 "\t" substr($1,1,4) "\t" substr($1,5,2) "\t" substr($1,7,2) "\t" substr($1,9,2)}' $infile > $outfile

[hadoop@hadoop000 hive_data]$ bash sogou-log-extend.sh /home/hadoop/data/hive_data/sogou.500w.utf8 /home/hadoop/data/hive_data/sogou.500w.utf8.ext

[hadoop@hadoop000 hive_data]$ less sogou.500w.utf8.ext
20111230000005  57375476989eea12893c0c3811607bcf        奇艺高清        1       1       http://www.qiyi.com/    2011    12      30      00
20111230000005  66c5bb7774e31d0a22278249b26bc83a        凡人修仙传      3       1       http://www.booksky.org/BookDetail.aspx?BookID=1050804&Level=1   2011    12      30      00
20111230000007  b97920521c78de70ac38e3713f524b50        本本联盟        1       1       http://www.bblianmeng.com/      2011    12      30      00

数据加载

将数据加载到hdfs

hadoop fs -mkdir -p /sogou/20111230
hadoop fs -put  /home/hadoop/data/hive_data/sogou.500w.utf8  /sogou/20111230/
hadoop fs -mkdir -p /sogou_ext/20111230
hadoop fs -put  /home/hadoop/data/hive_data/sogou.500w.utf8.ext  /sogou_ext/20111230/

构建数据仓库

创建外部表

create external table if not exists sogou.sogou_20111230(
ts string,
uid string,
keyword string,
rank int,
order int,
url string)
comment 'This is the sogou search data of one day'
row format delimited
fields terminated by '\t'
stored as textfile
location '/sogou/20111230';

创建分区表

create external table if not exists sogou.sogou_ext_20111230(
ts string,
uid string,
keyword string,
rank int,
order int,
url string,
year int,
month int,
day int,
hour int)
comment 'This is the sogou search data of extend'
row format delimited
fields terminated by '\t'
stored as textfile
location '/sogou_ext/20111230';

create external table if not exists sogou.sogou_partition(
ts string,
uid string,
keyword string,
rank int,
order int,
url string)
comment 'This is the sogou search data by partition'
partitioned by(
year INT, month INT, day INT, hour INT)
row format delimited
fields terminated by '\t'
stored as textfile;

set hive.exec.dynamic.partition.mode=nonstrict;

insert overwrite table sogou.sogou_partition partition(year, month, day, hour) select * from sogou.sogou_ext_20111230;

select * from sogou_partition limit 10;

数据分析需求

条数统计

*数据总数*
select count(*) from sogou_ext_20111230;
*非空查询条数*
select count(*) from sogou_ext_20111230 where keyword is not null and keyword != ' ';
*无重复条数(根据ts,uid,keyword,url)*
select count(*) from (select ts,uid,keyword,url from sogou_ext_20111230 group by ts,uid,keyword,url  having count(*)=1) B;
*独立UID条数*
select count(distinct(uid)) from sogou_ext_20111230;

关键词分析

*关键词平均长度统计,关键词中没有空白字符,则长度为一*
select avg(a.cnt) from (select size(split(keyword,' s+')) as cnt from sogou_ext_20111230) a;

Total MapReduce CPU Time Spent: 19 seconds 870 msec
OK
1.0012018
Time taken: 28.049 seconds, Fetched: 1 row(s)

*查询频度排名*
select  keyword,count(*) as cnt from sogou_ext_20111230 group by keyword order by cnt desc limit 10;

Total MapReduce CPU Time Spent: 43 seconds 440 msec
OK
百度	38441
baidu	18312
人体艺术	14475
4399小游戏	11438
qq空间	10317
优酷	10158
新亮剑	9654
馆陶县县长闫宁的父亲	9127
公安卖萌	8192
百度一下 你就知道	7505
Time taken: 64.503 seconds, Fetched: 10 row(s)

UID分析

*查询一次,两次,三次,大于三次的UID数量*
select sum(if(uids.cnt=1,1,0)),sum(if(uids.cnt=2,1,0)),sum(if(uids.cnt=3,1,0)),sum(if(uids.cnt>3,1,0)) from (select uid,count(*) as cnt from sogou_ext_20111230 group by uid) uids;

Total MapReduce CPU Time Spent: 34 seconds 600 msec
OK
549148	257163	149562	396791
Time taken: 56.256 seconds, Fetched: 1 row(s)

*UID平均查询次数*
select sum(uids.cnt)/count(uids.uid) from (select uid,count(*) as cnt from sogou_ext_20111230 group by uid) uids;

Total MapReduce CPU Time Spent: 28 seconds 400 msec
OK
3.6964094557111005
Time taken: 49.467 seconds, Fetched: 1 row(s)

*查询次数大于两次的用户总数*
select sum(if(uids.cnt>2,1,0)) from (select uid,count(*) as cnt from sogou_ext_20111230 group by uid) uids;

Total MapReduce CPU Time Spent: 31 seconds 520 msec
OK
546353
Time taken: 51.733 seconds, Fetched: 1 row(s)

*查询次数大于两次的用户所占比*
分开计算,然后相除。

用户行为分析

点击次数与rank之间的关系分析

select count(*) as cnt from sogou_ext_20111230 where rank<11;

Total MapReduce CPU Time Spent: 13 seconds 230 msec
OK
4999869
Time taken: 23.677 seconds, Fetched: 1 row(s)

总数为500万,比例为4999869/5000000,可看出,绝大部分会点击前10条搜索结果。

直接输入URL作为查询词的比例

*直接输入URL查询的比例*
select count(*) from sogou_ext_20111230 where keyword like '%www%';

Total MapReduce CPU Time Spent: 12 seconds 390 msec
OK
73979
Time taken: 24.717 seconds, Fetched: 1 row(s)

*直接输入URL查询并且查询的URL位于点击的URL中*
select sum(if(instr(url,keyword)>0,1,0)) from (select * from sogou_ext_20111230 where keyword like '%www%') a;

Total MapReduce CPU Time Spent: 12 seconds 600 msec
OK
27561
Time taken: 23.817 seconds, Fetched: 1 row(s)

可看出大部分搜索URL,并不能得到自己想要的结果。

独立用户行为分析

搜索个人的行为,此处略。
  • 11
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在进行大数据财务分析时,可以使用Python作为编程语言来处理和分析数据。Python有丰富的数据处理和分析库,如Pandas、NumPy和Matplotlib,可以帮助处理大规模的数据集和生成可视化报告。此外,还可以使用开源的分布式SQL查询引擎Presto来进行交互式的分析查询。Presto适用于处理大规模的数据,并可以实现快速的交互式分析。它可以对250PB以上的数据进行快速地交互式分析,并且在处理速度方面比传统的查询引擎如Hive和MapReduce要好上10倍以上。 另外,Amazon Kinesis Streams是一个用于处理流数据的服务,可以从数十万种来源中连续捕获和存储大量的数据。它可以用于收集和分析网站点击流、财务交易、社交媒体源、IT日志和定位追踪事件等数据,满足大数据财务分析的需求。 对于商务智能方面的需求,可以使用开源的商务智能软件Pentaho。Pentaho是一个基于Java平台的商业智能套件,包括报表、分析、图表、数据集成、数据挖掘等工具软件。它以工作流为核心,强调面向解决方案而非工具组件,可以满足商务智能的各个方面的需求。 综上所述,大数据财务分析可以基于Python编程语言进行处理和分析数据,并可以借助Presto进行交互式查询和分析。此外,Amazon Kinesis Streams可以用于处理流数据,而Pentaho则是一个全面的商务智能套件,可满足各种商务智能需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值