对于两个输入文件,即文件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: 未 ...
随机推荐
- MVC中Bundle的使用
BundleConfig配置 (1)StyleBundle中的参数,即为cshtml中需要调用的虚拟路径名称. (2)Include包含路径,可以包含一个或多个css或js文件.即包含一组文件. pu ...
- C语言测一个浮点数的位数长度
测浮点数的位数牵扯到一个精度的问题,用普通的测整形数值的方法不能实现,于是我自己写了一个测浮点数的函数. #include <stdio.h> //for printf int lengt ...
- Python输出HelloWorld(以及环境配置)
java usebean 用法: https://blog.csdn.net/zhang150114/article/details/89434617
- java内置锁实现锁住代码块方案(同一个对象或锁住整个类.class)
我们看一个例子: class Demo { public synchronized void test() { System.out.println("test方法开始执行,当前线程为:&q ...
- Adnc简介
Adnc是一个轻量级的.Net Core微服务(microservices)快速开发框架,同时也可以应用于单体架构系统的开发.框架基于JWT认证授权,包含基础的后台管理功能,代码简洁.易上手.学习成本 ...
- node使用xlsx导入导出excel
1.安装和引入xlsx 安装 npm install xlsx 引入:let xlsx = require('xlsx');2.读取excel数据function readFile(file) { ...
- python之shelve、xml、configparser模块
一.shelve模块 shelve模块比pickle模块简单,只有一个open函数,返回类似字典的对象,可读可写;key必须为字符串,而值可以是python所支持的数据类型 import shelve ...
- python之logging 模块(下篇)
四.日志处理流程(第二种日志使用方式) 上面简单配置的方法例子中我们了解到了logging.debug().logging.info().logging.warning().logging.error ...
- EF Core CodeFirst数据库自动迁移
开发过程中都会遇到数据库数据结构更新的问题,怎么对数据库更新进行版本控制呢? 不同的项目对数据库版本更新控制的方式不同,常用的有第三方Evolve,开发人员将数据库更新脚本按照版本号的放在一起,然后执 ...
- Servlet[JAX-RS Servlet]的Servlet.init()引发异常
代码环境 Eclipse2017 : 问题出现: 在测试Hello servlet时发生 org.apache.catalina.core.ApplicationContext log严重: Serv ...