



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
答案1. 选择题(1) D解释:A,B,C都可以。(2) A解释:单词折分是通过调用类StringTokenizer实现,单词在mapper中映射为(word,one)。(3) B解释:排序发生在数据混洗阶段。(4) C解释:setInputFormat。(5) D解释:“Alice”对应Text,89.5对应Double类型,组合输出为(Text,Double)(6) A解释:自定义Mapper模块必须继承Mapper。(7) C(8) B解释:setup,reduce,cleanup。(9) B解释:输出的键值对默认按KEY的ASCII码进行排序。(10) B解释:可省略Mapper端的输出格式设置。2. 操作题(1) 使用有短句“A friend in need is a friend in deed”,画出使用MapReduce对它进行词频统计的过程,主要展示Map阶段与Reduce阶段的处理过程。如图 1所示。图 1 MapReduce词频统计过程(2) 具体实现代码如代码 1所示。代码 1 实现代码 HadoopCount.java内容package test;import java.io.IOException;import java.util.StringTokenizer;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.Job;import org.apache.hadoop.mapreduce.Mapper;import org.apache.hadoop.mapreduce.Reducer;import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import org.apache.hadoop.util.GenericOptionsParser;public class HadoopCount public static class MyMapper extends Mapper private final static IntWritable one = new IntWritable(1);private String str; private Text word=new Text(); public void map(Object key, Text value, Context context ) throws IOException, InterruptedException StringTokenizer itr = new StringTokenizer(value.toString(); while (itr.hasMoreTokens() str=itr.nextToken(); if(str.equals(Hadoop)word.set(str); context.write(word, one); public static class MyReducer extends Reducer private IntWritable result = new IntWritable(); public void reduce(Text key, Iterable values, Context context ) throws IOException, InterruptedException int sum = 0; for (IntWritable val : values) sum += val.get(); result.set(sum); context.write(key,result); public static void main(String args) throws Exception Configuration conf = new Configuration(); String otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length 2) System.err.println(Usage: wordcount . ); System.exit(2); Job job = new Job(conf, Word Hadoop Count); job.setJarByClass(HadoopCount.class); job.setMapperClass(MyMapper.class); job.setReducerClass(MyReducer.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(IntWritable.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); for (int i = 0; i otherArgs.length - 1; +i) FileInputFormat.addInputPath(job, new Path(otherArgsi);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度高品质砂砾石开采及深加工项目合同
- 股权期权合同协议书模板范本
- 2025《中文合同编写要领》教程
- 2025承诺的借款合同样本
- 医疗器械销售合同新
- 发行权转让合同
- 2025年数字货币在智慧林业领域的应用与监管研究报告
- 2025年商业店铺租赁合同书(合同范本)
- 2025年拟签订的合同范本
- 2025年文化旅游演艺项目可持续发展策划与运营策略报告
- 中国钼金属行业市场调查报告
- 物业追缴奖励方案(3篇)
- 华为公司组织管理制度
- 2025年中国蛋白肽市场现状分析及前景预测报告
- 幼儿大班如厕教学课件
- 2025年智慧城市产业园区开发建设社会稳定风险评估与风险防范对策报告
- 《医疗机构工作人员廉洁从业九项准则》解读
- Axure RP 互联网产品原型设计课件 第10章 团队合作与输出
- 《支架外固定的护理》课件
- 农村公路养护管理讲座
- 以房抵债协议书二零二五年
评论
0/150
提交评论