




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、8. 在 Eclipse 中运行“Word Count” MapReduce 程序(1)在 Eclipse 中创建 “WordCount” MapReduce 项目点击File菜单,选择 New - Project:选择Map/Reduce Project,点击 Next:填写 Project name为 MyWordCount,点击 Finish 创建项目。MyWordCount 项目,选择 New - Class:在 Name 处填写 WordCountTest。将如下 WordCountTest 的代码到该 WordCountTest.java 中。import java.io.IOEx
2、ception; import java.util.Iterator;import java.util.StringTokenizer;import.apache.hadoop.conf.Configuration; import.apache.hadoop.fs.Path;import.apache.hadoop.io.Writable; import.apache.hadoop.io.Text;import.apache.hadoop.mapreduce.Job; import.apache.hadoop.mapreduce.Mapper; import.apache.hadoop.map
3、reduce.Reducer;import.apache.hadoop.mapreduce.lib.input.FileInputFormat;importimport.apache.hadoop.mapreduce.lib.output.FileOutputFormat;.apache.hadoop.util.GenericOptionsParser;public class WordCountTest public WordCountTest() public sic void main(String args) throws Exception Configuration conf =
4、new Configuration();String otherArgs = (new GenericOptionsParser(conf, args).getRemainingArgs(); if(otherArgs.length 2) System.err.prln(Usage: wordcount . ); System.exit(2);Job job = Job.getInstance(conf, word count test); job.setJarByClass(WordCountTest.class); job.setMapperClass(WordCountTest.Toke
5、nizerMapper.class);binerClass(WordCountTest.SumReducer.class); job.setReducerClass(WordCountTest.SumReducer.class); job.setOutputKeyClass(Text.class);job.setOutputValueClass(Writable.class);for(i = 0; i otherArgs.length - 1; +i) FileInputFormat.addInputPath(job, neth(otherArgsi);FileOutputFormat.set
6、OutputPath(job, neth(otherArgsotherArgs.length - 1);System.exit(pletion(true)?0:1);public sic classSumReducer extends Reducer privateWritable result = newWritable();publicSumReducer() public void reduce(Text key, Iterable values, Reducer.Context context) throws IOException,sum = 0;erruptedException
7、Writable val;for(Iterator itr = values.iterator(); itr.hasNext(); sum += val.get() val = (Writable)itr.next();(2)将 Hadoop 配置文件添加到“WordCount” MapReduce 项目将 perties中:到 WordCount 项目下的 src 文件夹(/workspace/WordCount/src)og4j 用于程序的输出,需要 perties 这个配置文件,如果没有该文件到项目中,运行程序后在 Console 面板中会出现警告提示
8、:log4j:WARNNoappenderscouldbefoundforlogger虽然不影响程序的正确运行的,但程序运行时无法看到任何提示消息(只能看到出错信息)。完成后,务必WordCount 选择 refresh 进行刷新(不会自动刷新,需要手动刷新),可以看到文件结构如下所示:(.apache.hadoop.metrics2.lib.MutableMetricsFactory).log4j:WARN Please initialize the log4j system properly.log4j:WARN Seefor more info.hfutmaster $ cp /hado
9、op-2.5.2/etc/hadoop/perties /workspace/MyWordCount/srcthis.result.set(sum); context.write(key, this.result);public sic class TokenizerMapper extends Mapper private sic finalWritable one = newWritable(1);private Text word = new Text();public TokenizerMapper() publicvoidmap(Objectkey,Textvalu
10、e,Mapper.Context context) throws IOException,erruptedException StringTokenizer itr = new StringTokenizer(value.toString();while(itr.hasMoreTokens() this.word.set(itr.nextToken(); context.write(this.word, one);(3)通过 Eclipse 运行“MyWordCount” MapReduce 项目点击中的 Run 图标,或者Project Explorer 中的 WordCountTest.java,选择Run As - Run on Hadoop,就可以运行 MapReduce 程序了。不过由于没有指定参数,运行时会提示 “Usage: wordcount”,需要通过 Eclipse 设定一下运行参数。刚创建的 WordCount.java,选择 Run As - Run Configurations,在此处可以设置运行时的相关参数( 如果 Java Application 下面没有 WordCount, 那么需要先双击 JavaApplication )。 切 换 到“ Arguments ”, 在Program arguments 处填写
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025财务专项资金监管合同
- 2025年合同法与旧合同法:新旧规定对比解析
- 2025标准的采购合同范本示例
- 2025农村合作银行社团贷款合同
- 2025年激光扫描绘图机项目发展计划
- 2025年土地流转合同范本正式版
- 医药行业中医药现代化研发方案
- 中国传统家具史知到课后答案智慧树章节测试答案2025年春宁波大学
- 中国典籍外译知到课后答案智慧树章节测试答案2025年春山东建筑大学
- 新能源项目风险评估与应对策略指南
- 信用风险度量第六章-KMV模型课件
- 小学硬笔书法课教案(1-30节)
- 基于CAN通讯的储能变流器并机方案及应用分析报告-培训课件
- 医院清洁消毒与灭菌课件
- 消防安装工程施工方案Word版
- 软管管理规定3篇
- 关于对领导班子的意见和建议
- 【课件】学堂乐歌 课件-2022-2023学年高中音乐人音版(2019)必修音乐鉴赏
- 纳布啡在胃肠镜麻醉中的临床观察-课件
- 常用手术器械手工清洗
- 2022中西医执业医师实践技能疾病对照诊断内科
评论
0/150
提交评论