没有合适的资源?快使用搜索试试~ 我知道了~
首页大数据综合案例-搜狗搜索日志分析(修复版final).doc
资源详情
资源评论
资源推荐
一、 数据预处理(Linux 环境)
数据下载百度云链接
链接:hps://pan.baidu.com/s/1GtWNEkrBBZQq7AIvzksTEA
提取码:6nal
复制这段内容后打开百度网盘手机 App,操作更方便哦
搜狗数据的数据格式:
访问时间用户查询词该在返回结果中的排名用户点击的顺序号用户点击
的
其中,用户是根据用户使用浏览器访问搜索引擎时的信息自动赋值,即同一次使
用浏览器输入的不同查询对应同一个用户。
查看数据
————————————————
原始数据格式:
查看总行数:
数据处理
将时间字段拆分并拼接,添加年、月、日、小时字段
3.数据过滤
过滤第 2 个字段(UID)或者第 3 个字段(搜索关键词)为空的行(需要用第 2 步数据
扩展的结果)
package com.hz.sougou;
public class SougouUtils {
public static String DateString(String str){
StringBuilder sb = new StringBuilder();
String[] split = str.split("\t");
// System.out.println(split.length);
if (split.length < 6) return null;
if (split[1] == null) return null;
if (split[2] == null) return null;
String date = split[0];
String year,month,day,hour;
year = date.substring(0, 4);
month = date.substring(4, 6);
day = date.substring(6, 8);
hour = date.substring(8, 10);
sb.append(str+"\t"+year+"\t"+month+"\t"+day+"\t"+hour);
return sb.toString();
}
// public static void main(String[] args) {
// String str = "20111230000003 addf4b43f7782807bb19155a3c7f8465
htc g10 1 1
http://product.pchome.net/mobile_phone_htc_htcdesirehd/288412.html";
//// DateString(str);
// System.out.println(DateString(str));
// }
}
package com.hz.sougou;
import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class SougouMapper extends Mapper<LongWritable, Text, Text,
NullWritable>{
Text mapOutPutkey = new Text();
@Override
protected void map(LongWritable key, Text value,Context context)
throws IOException, InterruptedException {
String str = value.toString();
String line = SougouUtils.DateString(str);
mapOutPutkey.set(line);
context.write(mapOutPutkey, NullWritable.get());
}
}
package com.hz.sougou;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class SougouRunner extends Configured implements Tool{
public int run(String[] args) throws Exception {
Configuration conf = super.getConf();
Job job = Job.getInstance(conf);
job.setJarByClass(getClass());
// set Map inputPath
Path inPath = new Path(args[0]);
FileInputFormat.addInputPath(job, inPath);
job.setMapperClass(SougouMapper.class);
// set map out key&value de type
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(NullWritable.class);
Path outPath = new Path(args[1]);
FileSystem dfs = FileSystem.get(conf);
if (dfs.exists(outPath)) {
dfs.delete (outPath) ;
}
FileOutputFormat.setOutputPath(job, outPath);
// 4.Submit Job
boolean isSuccess = job.waitForCompletion(true);
return isSuccess ? 0 : 1;
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
// args = new String[]
{ "hdfs://hadoo.com:8020/track_log/","hdfs://hadoop.com:8020/output"};
args = new String[]
{"hdfs://master:8020/log/sogou.500w.utf8","hdfs://master:8020/outsougou/"};
int status = ToolRunner.run(conf, new SougouRunner(),args);
// exit program
System.exit(status);
}
}
查看清洗后的数据
基于 HIve 构建日志数据的数据仓库
创建数据库
使用数据库
创建扩展 4 个字段(年、月、日、小时)数据的外部表:
!" #" $!"!% &'
()
()
*+()
(()
()
,()
*()
-(()
*()
(.
/01/2!" 2"
1 3" 2$!" %455
3"/ !3" #"1
/6
"-(789(
表加载数据
,(:5;;&,<=5(,&
剩余44页未读,继续阅读
johnny00000
- 粉丝: 12
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0