对于两个输入文件,即文件A 和文件B ,请编写MapReduce程序,对两个文件进行合并排除其中重复的内容,得到一个新的输出文件C。
package org.apache.hadoop.examples;
import java.util.HashMap;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
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 A_formatSameString {
public A_formatSameString() {
}
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: wordcount <in> [<in>...] <out>");
System.exit(2);
}
Job job = Job.getInstance(conf, "clearSame");
job.setJarByClass(A_formatSameString.class);
job.setMapperClass(A_formatSameString.TokenizerMapper.class);
job.setCombinerClass(A_formatSameString.IntSumReducer.class);
job.setReducerClass(A_formatSameString.IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
for(int i = 0; i < otherArgs.length - 1; ++i) {
FileInputFormat.addInputPath(job, new Path(otherArgs[i]));
}
FileOutputFormat.setOutputPath(job, new Path(otherArgs[otherArgs.length - 1]));
System.exit(job.waitForCompletion(true)?0:1);
}
public static class IntSumReducer extends Reducer<Text, Text, Text, Text> {
private Text word2 = new Text();
public IntSumReducer() {
}
public void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, Text, Text>.Context context) throws IOException, InterruptedException {
Map dict = new HashMap();
for(Iterator i$ = values.iterator(); i$.hasNext(); ) {
Text value = (Text)i$.next();
if(!dict.containsKey(value)){
dict.put(value,1);
this.word2.set(value);
context.write(key, this.word2);
}
}
//System.out.println(key.toString()+"\n"+result.toString());
}
}
public static class TokenizerMapper extends Mapper<Object, Text, Text, Text> {
private static final IntWritable one = new IntWritable(1);
private Text word = new Text();
private Text word2 = new Text();
public TokenizerMapper() {
}
public void map(Object key, Text value, Mapper<Object, Text, Text, Text>.Context context) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
//System.out.println(itr.toString());
while(itr.hasMoreTokens()) {
String tmpstr = itr.nextToken();
String tmpstr2 = itr.nextToken();
this.word.set(tmpstr);
this.word2.set(tmpstr2);
//System.out.println(tmpstr);
context.write(this.word, this.word2);
}
}
}
}
对于两个输入文件,即文件A 和文件B ,请编写MapReduce程序,对两个文件进行合并排除其中重复的内容,得到一个新的输出文件C。的更多相关文章
- 编写Java程序,在硬盘中选取一个 txt 文件,读取该文档的内容后,追加一段文字“[ 来自新华社 ]”,保存到一个新的 txt 文件内
查看本章节 查看作业目录 需求说明: 在硬盘中选取一个 txt 文件,读取该文档的内容后,追加一段文字"[ 来自新华社 ]",保存到一个新的 txt 文件内 实现思路: 创建 Sa ...
- 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误消息: CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\41c191fd\ff9345c5\App_Web_login.cshtml.65793277
本地开发环境没问题,但是发布到服务器出现问题或则直接在IIS上修改东西就给我抛出以下错误: 未能写入输出文件"c:\Windows\Microsoft.NET\Framework64 \v4 ...
- C#与dotNET项目想要另存为一个新项目sln文件丢了怎么办
如下图所示,我想要另存一个工程,把 V4.4整个的项目另存为V4.5,我可以把解决方案文件(.sln)改名字,但是我没法把文件夹改名字,改了打开sln就说找不到. 很简单的一个思路是反正sln是多余的 ...
- Laptop Issue Letter (读取Excel中指定内容,然后生成新的Excel文件)
$xl = New-Object -ComObject "Excel.Application" $cmdbwb = $xl.Workbooks.Open("F:\Ivan ...
- 一个JSON字符串和文件处理的命令行神器jq,windows和linux都可用
这个命令行神器的下载地址:https://stedolan.github.io/jq/# Windows和Linux版本均只有两个可执行文件,大小不过2MB多. 以Windows版本为例,介绍其用法. ...
- CS0016: 未能写入输出文件“c:\WINDOWS\Microsoft.NET\Framework\.。。”--“拒绝访问
aspx 常见错误 CS0016: 未能写入输出文件“c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/... ...
- Win7下:编译器错误信息: CS0016: 未能写入输出文件
错误如下: "/"应用程序中的服务器错误. 编译错误 说明: 在编译向该请求提供服务所需资源的过程中出现错误.请检查下列特定错误详细信息并适当地修改源代码. 编译器错误消息: CS ...
- 编译器错误消息: CS0016: 未能写入输出文件“c:/Windows/Microsoft.NET/Framework/v2.0.50727/....dll”--“拒绝访问。
错误如下: “/”应用程序中的服务器错误. 编译错误 说明: 在编译向该请求提供服务所需资源的过程中出现错误.请检查下列特定错误详细信息并适当地修改源代码. 编译器错误消息: CS0016: 未能写入 ...
- 访问svc 文件,编译器错误消息: CS0016,未能写入输出文件
编译错误 说明: 在编译向该请求提供服务所需资源的过程中出现错误.请检查下列特定错误详细信息并适当地修改源代码. 编译器错误消息: CS0016: 未 ...
随机推荐
- C#中的深度学习(四):使用Keras.NET识别硬币
在本文中,我们将研究一个卷积神经网络来解决硬币识别问题,并且我们将在Keras.NET中实现一个卷积神经网络. 在这里,我们将介绍卷积神经网络(CNN),并提出一个CNN的架构,我们将训练它来识别硬币 ...
- fiddler抓APP的https接口
吐槽一下,fiddler这工具很蛋疼,用的时候很好用,出bug的时候死活抓不了: ①为了少踩坑,我们在官网下最新的fiddler,官网:Fiddler - Free Web Debugging Pro ...
- npm 各种常用命令
全局删除 node-gyp npm -g uninstall node-gyp 再次安装依赖 npm install 更改包内容后重建 npm rebuild 清除缓存 npm cache clean ...
- 熬夜肝了这篇Spring Cloud Gateway的功能及综合使用
前言 SpringCloud 是微服务中的翘楚,最佳的落地方案. Spring Cloud Gateway 是 Spring Cloud 新推出的网关框架,之前是 Netflix Zuul.网关通常在 ...
- 英特尔® 图形性能分析器(Intel® GPA)
英特尔图形性能分析器概述 英特尔 GPA 是一套软件工具,它能提供平台级游戏性能分析功能,优化应用性能. 英特尔 GPA 包含以下组件: 英特尔 GPA 监控器 - 将英特尔 GPA 连接至应用(处于 ...
- 关于eclipse反编译插件不起作用问题的解决
1.首先我的eclipse版本是 Version: Photon Release (4.8.0),小伙伴们可以通过 help>>About eclipse IDE 来查看自己的eclips ...
- break continue学习
1.break和continue必须使用在循环或者switch语句中 2.当break语句单独存在时.后面不要定义其他语句,因为后面的语句无法执行到 3.break跳出当前所在循环 4.break跳出 ...
- Linux系统下qt程序运行找不到IGL
linux下使用QT5运行时出现两个问题: cannot find -lGL collect2:error:ld returned 1 exit status 这是因为系统缺少链接库,执行两条命令即可 ...
- Mysql Cluster7.5.6 windows10 部署安装
部署方法网上很多,以下是我的实践过程,供大家参考. 1. 硬件:3台虚拟机,全是windows 10 x64 2. 网络架构: 管理节点:192.168.37.128 数据节点 / SQL节点: 19 ...
- 如何下载youtube的视频?
导言 当youtube视频需要下载时,发现需要会员等其他限制 别急,下面就是比较稳定的方法 准备 gitub链接 youtube-dl github 官网链接 官网 按照官网提示下载对应版本 我这里是 ...