使用eclipse的快捷键自动生成的map或者reduce函数的参数中:“org.apache.hadoop.mapreduce.Reducer.Context context”
今天在测试mapreduce的程序时,就是简单的去重,对照课本上的程序和自己的程序,唯一不同的就是“org.apache.hadoop.mapreduce.Reducer.Context context”,我写的程序如下:
package com.pro.bq; import java.io.IOException; 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 Dedup {
public static class Map extends Mapper<Object,Text, Text, Text>{
private Text line=new Text(); @Override
protected void map(Object key, Text value,
Context context)
throws IOException, InterruptedException {
// TODO Auto-generated method stub
line=value;
context.write(line, new Text("")); } }
public static class Reduce extends Reducer<Text, Text, Text, Text>
{ @SuppressWarnings("unchecked")
protected void reduce(Text key, Iterable<Text> value,
org.apache.hadoop.mapreduce.Reducer.Context context)
throws IOException, InterruptedException {
// TODO Auto-generated method stub
context.write(key, new Text("")); }
}
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
Configuration conf=new Configuration();
// conf.set("mapred.job.tracker", "localhost:9001");
String hdfs=new String("hdfs://localhost:9000/user/haduser/");
String[] ioStr=new String[]{hdfs+"input",hdfs+"output/outDedup"}; //自己在代码中定义路径,否则的话就要就要在程序的输入参数中设置了
String[] otherStr=new GenericOptionsParser(conf, ioStr).getRemainingArgs(); if(otherStr.length!=2)
{
System.err.println("Usage: Data deduplication <in> <out>");
System.exit(2);
} Job job=new Job(conf, "Data deduplication");
job.setJarByClass(Dedup.class); job.setMapperClass(Map.class);
job.setCombinerClass(Reduce.class);
job.setReducerClass(Reduce.class); job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class); FileInputFormat.addInputPath(job, new Path(otherStr[0]));
FileOutputFormat.setOutputPath(job, new Path(otherStr[1]));
System.exit(job.waitForCompletion(true) ? 0:1); } }
课本上给出的程序如下:
package com.pro.bq; import java.io.IOException; 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 Dedup {
public static class Map extends Mapper<Object,Text, Text, Text>{
private Text line=new Text(); protected void map(Object key, Text value,
Context context)
throws IOException, InterruptedException {
// TODO Auto-generated method stub
line=value;
context.write(line, new Text("")); } }
public static class Reduce extends Reducer<Text, Text, Text, Text>
{ protected void reduce(Text key, Iterable<Text> value,
Context context)
throws IOException, InterruptedException {
// TODO Auto-generated method stub
context.write(key, new Text("")); }
}
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
Configuration conf=new Configuration();
// conf.set("mapred.job.tracker", "localhost:9001");
String hdfs=new String("hdfs://localhost:9000/user/haduser/");
String[] ioStr=new String[]{hdfs+"input",hdfs+"output/outDedup"}; //自己在代码中定义路径,否则的话就要就要在程序的输入参数中设置了
String[] otherStr=new GenericOptionsParser(conf, ioStr).getRemainingArgs(); if(otherStr.length!=2)
{
System.err.println("Usage: Data deduplication <in> <out>");
System.exit(2);
} Job job=new Job(conf, "Data deduplication");
job.setJarByClass(Dedup.class); job.setMapperClass(Map.class);
job.setCombinerClass(Reduce.class);
job.setReducerClass(Reduce.class); job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class); FileInputFormat.addInputPath(job, new Path(otherStr[0]));
FileOutputFormat.setOutputPath(job, new Path(otherStr[1]));
System.exit(job.waitForCompletion(true) ? 0:1); } }
测试的文件file1.txt是:
2012-3-1 a
2012-3-2 b
2012-3-3 c
2012-3-4 d
2012-3-5 a
2012-3-6 b
2012-3-7 c
2012-3-3 c
file2.txt:
2012-3-1 b
2012-3-2 a
2012-3-3 b
2012-3-4 d
2012-3-5 a
2012-3-6 c
2012-3-7 d
2012-3-3 c
按照我写的运行的结果是:
2012-3-1 a
2012-3-1 b
2012-3-2 a
2012-3-2 b
2012-3-3 b
2012-3-3 c
2012-3-3 c
2012-3-3 c
2012-3-4 d
2012-3-4 d
2012-3-5 a
2012-3-5 a
2012-3-6 b
2012-3-6 c
2012-3-7 c
2012-3-7 d
想要的结果是:
2012-3-1 a
2012-3-1 b
2012-3-2 a
2012-3-2 b
2012-3-3 b
2012-3-3 c
2012-3-4 d
2012-3-5 a
2012-3-6 b
2012-3-6 c
2012-3-7 c
2012-3-7 d
不知道为什么?暂且记下,有懂的希望不吝赐教,我是菜鸟...
使用eclipse的快捷键自动生成的map或者reduce函数的参数中:“org.apache.hadoop.mapreduce.Reducer.Context context”的更多相关文章
- 【hadoop】如何向map和reduce脚本传递参数,加载文件和目录
本文主要讲解三个问题: 1 使用Java编写MapReduce程序时,如何向map.reduce函数传递参数. 2 使用Streaming编写MapReduce程序(C/C++ ...
- (转)如何向map和reduce脚本传递参数
[MapReduce] 如何向map和reduce脚本传递参数,加载文件和目录 分类: hadoop2014-04-28 21:30 1553人阅读 评论(0) 收藏 举报 hadoop 本文主要讲解 ...
- 如何向map和reduce脚本传递参数,加载文件和目录
本文主要讲解三个问题: 1 使用Java编写MapReduce程序时,如何向map.reduce函数传递参数. 2 使用Streaming编写MapReduce程序(C/C++ ...
- java如何在eclipse编译时自动生成代码
用eclipse写java代码,自动编译时,如何能够触发一个动作,这个动作是生成本项目的代码,并且编译完成后,自动生成的代码也编译好了, java编辑器中就可以做到对新生成的代码的自动提示? 不生成代 ...
- 利用Eclipse的JPA自动生成注解实体
新公司用的SSH(springmvc)框架,看代码的时候,发现没有hbm.xml文件,全部使用的注解形式.在一次闲聊的时候问同事,这么多entity 写起来不麻烦么.同事说根据数据库自动生成的.于是 ...
- Intellij idea用快捷键自动生成序列化id
ntellij idea用快捷键自动生成序列化id 类继承了Serializable接口之后,使用alt+enter快捷键自动创建序列化id 进入setting→inspections→seriali ...
- WPF/C# 快捷键 自动生成方法
原文:WPF/C# 快捷键 自动生成方法 这一篇文章会很短~ 在写依赖属性的会后 propdb 会自动生成依赖属性所有的内容 但是如果我写属性变化通知的时候 希望有一个快捷键能自动生成方法 怎 ...
- vscode笔记(一)- vscode自动生成文件头部注释和函数注释
VsCode 自动生成文件头部注释和函数注释 作者:狐狸家的鱼 本文链接:vscode自动生成文件头部注释和函数注释 GitHub:sueRimn 1.安装插件KoroFileHeader 2.设置 ...
- sql自动生成汉语拼音和首字母函数
1.Sql server自动生成拼音的函数 /* 根据汉字获取全拼 1.生成所有读音临时表 2.根据Chinese_PRC_CS_AS_KS_WS 排序获取读音 */ )) ) as begin ) ...
随机推荐
- CentOS中操作Psql
psql -h 172.16.35.179 -U username -d dbname sername为数据库用户名,dbname为要连接的数据库名 查看现有的数据库: \l或\list 查看所有列 ...
- WebDev.WebServer40.exe已停止工作
今天写程序的遇到这个错误 错误的原因是代码中有死循环
- java抽象类和接口详解
接口和内部类为我们提供了一种将接口与实现分离的更加结构化的方法. 抽象类与接口是java语言中对抽象概念进行定义的两种机制,正是由于他们的存在才赋予java强大的面向对象的能力.他们两者之间对抽象概念 ...
- win7 telnet命令无法使用
很多做网络测试的同学发现安装win7后,无法使用telnet命令了,提示“telnet不是内部或外部命令,也不是可运行的程序”,但是很需要在win7中使用telnet工具,怎么办? 首先你要要确认你的 ...
- C# 连接 Oracle 的几种方式[转]
本文转自:http://www.cnblogs.com/storys/archive/2013/03/06/2945914.html 一:通过System.Data.OracleClient(需要安装 ...
- 2006: [NOI2010]超级钢琴 - BZOJ
Description小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号为1至n.第i个音符的美妙度为 ...
- c++ 从标注输入流读取行
#include <string.h> #include <iostream> #include <vector> #include <stdio.h> ...
- 垃圾回收 GC
垃圾回收器的回收的对象: 垃圾回收只回收托管堆中的内存 什么样的对象才会被回收? 没有变量引用的对象.没有变量引用的对象,表示可以被回收了(null. 什么时间回收? 不确定,当程序需要新内存 ...
- C# 客户端判断服务器连接已断开
问题描述: 在C# Socket编程中,服务器端已经断开连接(发送数据方),客户端接收服务器端发送数据,在客户端使用client.Recieve()中,服务器端断开连接,客户端任然显示已 ...
- 【Vijos】【1923】漫长的等待
可持久化线段树 这次是询问一段区间内权值 在给定范围内的点的数量,同样是可持久化线段树简单操作…… //Vijos 1923 #include<vector> #include<cs ...