- 1、本文档共9页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
基于 Hadoop 的数据分析
班级学号
专
实验学时
2
4.设置 eclipse 的 Java 环境:在 eclipse 下创建一个 jre 文件夹 sudo mkdir jre,进
入该文件夹:cd jre,
加入一条连接指令 ln -s /usr/lib/jvm/java-7-sun/bin bin
(2)在 eclipse 中添加 Map/Reduce:点击上方 window 选项,依次选择 open perspective,
other,Map、Reduce,如下图所示:
(3)设置 Map/Reduce location,选择 Map/Reduce locations,new hadoop location,
将其中的内容设置成下图所示的内容:
3
(4)设置 hadoop 的安装路径:依次点击 window,preferences,Hadoop Map/Reduce,设
置 hadoop 安装路径为/usr/local/hadoop
点击 Next,输入工程名为 average,再点击 finish。
(7)新建一个 Java class:右击左侧的 average,依次选择 New,class,设置内容如下
图所示:
4
package com.hebut.mr;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
public static class Map extends
5
while (tokenizerArticle.hasMoreElements()) {
// 每行按空格划分
StringTokenizertokenizerLine= newStringTokenizer(tokenizerArticle.nextToke
n());
}
public static class Reduce extends
ReducerText, IntWritable, Text, IntWritable {
// 实现 reduce 函数
}
int average = (int) sum / count;// 计算平均
context.write(key, new IntWritable(average));
}
conf.set(mapred.job.tracker, localhost:9001);
conf.set (mapred.jar, Score.jar);
String[] ioArgs = new String[] { score_in, score_out };
String[] otherArgs = new GenericOptionsParser(conf,
ioArgs).getRemainingArgs();
if (otherArgs.length != 2) {
6
System.err.println(Usage: Score Average in out);
System.exit(2);
}
Job job = new Job(conf, Score Average);
job.setJarByClass(Score.class)
// 设置 Map、Combine 和 Reduce 处理类
job.setMapperClass(Map.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
// 将输入的数据集分割成小数据块 splites,提供一个 RecordReder
的实现
job.setInputFormatClass(TextInputFormat.class);
// 提供一个 RecordWriter 的实现,负责数据输出
job.setOutputFormatClass(TextOutputFormat.class);
// 设置输入和输出目录
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])
);
}
System.exit(job.waitForCompletion(true) ? 0 : 1);
(注意将
文档评论(0)