- 1、本文档共7页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
实验3 MapReduce编程初级实践
实验3 MapReduce编程初级实践
实验目的
1.通过实验掌握基本的MapReduce编程方法;
2.掌握用MapReduce解决一些常见的数据处理问题,包括数据去重、数据排序和数据挖掘等。
实验平台
已经配置完成的Hadoop伪分布式环境。
实验内容和要求
1.编程实现文件合并和去重操作
对于两个输入文件,即文件A和文件B,请编写MapReduce程序,对两个文件进行合并,并剔除其中重复的内容,得到一个新的输出文件C。下面是输入文件和输出文件的一个样例供参考。
实验最终结果(合并的文件):
代码如下:
package com.Merge;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
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;
public class Merge {
public static class Map extends MapperObject, Text, Text, Text {
private static Text text = new Text();
public void map(Object key, Text value, Context context)
throws IOException, InterruptedException {
text = value;
context.write(text, new Text());
}
}
public static class Reduce extends ReducerText, Text, Text, Text {
public void reduce(Text key, IterableText values, Context context)
throws IOException, InterruptedException {
context.write(key, new Text());
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
conf.set(fs.defaultFS, hdfs://localhost:9000);
String[] otherArgs = new String[] { input, output };
if (otherArgs.length != 2) {
System.err.println(Usage: Merge and duplicate removal in out);
System.exit(2);
}
Job job = Job.getInstance(conf, Merge and duplicate removal);
job.setJarByClass(Merge.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(jo
您可能关注的文档
最近下载
- 2024年上海市普通高校招生本科艺术甲批次平行段院校专业组投档分数线美术与设计类.pdf VIP
- 2024入团共青团基础知识题库(含答案).docx
- 2024年在线网课学习课堂《健康管理科研思维训练(杭州师大 )》单元测试考核答案.pdf
- 2024年中国河南国际合作集团有限公司人员招聘考试题库及答案解析.docx
- 《骆驼祥子》读书分享PPT课件(精选图文).pptx
- 汉长安城遗址总体规划.pptx
- 欠钱不还的法院起诉书.docx VIP
- GB-T 10125-2012 人造气氛腐蚀试验 盐雾试验.pdf
- 新人教版七年级上册生物全册教案(2024年秋季新版教材).docx
- pcs-9651_080885技术和使用说明书.pdf
文档评论(0)