81 网站点击流数据分析案例(数据预处理功能)
- 转载:www.GuoXiongfei.cn
- /
- 时间:2019-08-15 16:16:30
- /
- 浏览:93,942次
- /
- 分类:css , Javascript , Java , DataBase , app
主要目的过滤“不合规”数据格式转换和规整根据后续的统计需求,过滤分离出各种不同主题的基础数据实现方式开发一个mr程序WeblogPreProcess:publicclassWeblogPreProcessstaticclassWeblogPreProcessMapperextendsMapper<LongWritable,Text,Text,NullWritable>Textk=new...

开发一个mr程序WeblogPreProcess:
public class WeblogPreProcess {static class WeblogPreProcessMapper extends Mapper<LongWritable, Text, Text, NullWritable> {Text k = new Text();NullWritable v = NullWritable.get();@Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {String line = value.toString();WebLogBean webLogBean = WebLogParser.parser(line);//WebLogBean productWebLog = WebLogParser.parser2(line);//WebLogBean bbsWebLog = WebLogParser.parser3(line);//WebLogBean cuxiaoBean = WebLogParser.parser4(line);if (!webLogBean.isValid())return;k.set(webLogBean.toString());context.write(k, v);//k.set(productWebLog);//context.write(k, v);}}public static void main(String[] args) throws Exception {Configuration conf = new Configuration();Job job = Job.getInstance(conf);job.setJarByClass(WeblogPreProcess.class);job.setMapperClass(WeblogPreProcessMapper.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(NullWritable.class);FileInputFormat.setInputPaths(job, new Path(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));job.waitForCompletion(true);}}
运行mr对数据进行预处理
hadoop jar weblog.jar cn.itcast.bigdata.hive.mr.WeblogPreProcess /weblog/input /weblog/preout点击流模型数据梳理
由于大量的指标统计从点击流模型中更容易得出,所以在预处理阶段,可以使用mr程序来生成点击流模型的数据。
1.点击流模型pageviews表Pageviews表模型数据生成
hadoop jar weblogpreprocess.jar \cn.itcast.bigdata.hive.mr.ClickStreamThree\/user/hive/warehouse/dw_click.db/test_ods_weblog_origin/datestr=2013-09-20/ /test-click/pageviews/
表结构:
注:“一次访问”=“N次连续请求”
直接从原始数据中用hql语法得出每个人的“次”访问信息比较困难,可先用mapreduce程序分析原始数据得出“次”信息数据,然后再用hql进行更多维度统计
用MR程序从pageviews数据中,梳理出每一次visit的起止时间、页面信息。
hadoop jar weblogpreprocess.jar cn.itcast.bigdata.hive.mr.ClickStreamVisit /weblog/sessionout /weblog/visitout
然后,在hive仓库中建点击流visit模型表
drop table if exist click_stream_visit;create table click_stream_visit(session string,remote_addr string,inTimestring,outTime string,inPagestring,outPage string,referal string,pageVisits int)partitioned by (datestr string);
然后,将MR运算得到的visit数据导入visit模型表
load data inpath '/weblog/visitout' into table click_stream_visit partition(datestr='2013-09-18');
源文地址:https://www.guoxiongfei.cn/csdn/7553.html