今天在测试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”的更多相关文章

  1. 【hadoop】如何向map和reduce脚本传递参数,加载文件和目录

    本文主要讲解三个问题:       1 使用Java编写MapReduce程序时,如何向map.reduce函数传递参数.       2 使用Streaming编写MapReduce程序(C/C++ ...

  2. (转)如何向map和reduce脚本传递参数

    [MapReduce] 如何向map和reduce脚本传递参数,加载文件和目录 分类: hadoop2014-04-28 21:30 1553人阅读 评论(0) 收藏 举报 hadoop 本文主要讲解 ...

  3. 如何向map和reduce脚本传递参数,加载文件和目录

    本文主要讲解三个问题:       1 使用Java编写MapReduce程序时,如何向map.reduce函数传递参数.       2 使用Streaming编写MapReduce程序(C/C++ ...

  4. java如何在eclipse编译时自动生成代码

    用eclipse写java代码,自动编译时,如何能够触发一个动作,这个动作是生成本项目的代码,并且编译完成后,自动生成的代码也编译好了, java编辑器中就可以做到对新生成的代码的自动提示? 不生成代 ...

  5. 利用Eclipse的JPA自动生成注解实体

    新公司用的SSH(springmvc)框架,看代码的时候,发现没有hbm.xml文件,全部使用的注解形式.在一次闲聊的时候问同事,这么多entity  写起来不麻烦么.同事说根据数据库自动生成的.于是 ...

  6. Intellij idea用快捷键自动生成序列化id

    ntellij idea用快捷键自动生成序列化id 类继承了Serializable接口之后,使用alt+enter快捷键自动创建序列化id 进入setting→inspections→seriali ...

  7. WPF/C# 快捷键 自动生成方法

    原文:WPF/C# 快捷键 自动生成方法 这一篇文章会很短~ 在写依赖属性的会后   propdb 会自动生成依赖属性所有的内容 但是如果我写属性变化通知的时候   希望有一个快捷键能自动生成方法 怎 ...

  8. vscode笔记(一)- vscode自动生成文件头部注释和函数注释

    VsCode 自动生成文件头部注释和函数注释 作者:狐狸家的鱼 本文链接:vscode自动生成文件头部注释和函数注释 GitHub:sueRimn 1.安装插件KoroFileHeader 2.设置 ...

  9. sql自动生成汉语拼音和首字母函数

    1.Sql server自动生成拼音的函数 /* 根据汉字获取全拼 1.生成所有读音临时表 2.根据Chinese_PRC_CS_AS_KS_WS 排序获取读音 */ )) ) as begin ) ...

随机推荐

  1. python学习小结7:变量类型

    变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间. 基于变量的数据类型,解释器会分配指定内存,并决定什么数据可以被存储在内存中. 因此,变量可以指定不同的数据类型,这些变量可以存储整 ...

  2. Codeforces Round #321 (Div. 2) D. Kefa and Dishes 状压dp

    题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 W ...

  3. zend studio 10 字体,颜色,快捷键等相关设置

    一.修改字体 没想到zend studio 10中对中文显示不太好看,似乎有点小了.修改如下:打开 Window->Preferences->General->Appearance- ...

  4. c++中new和delete的使用方法

    c++中new和delete的使用方法 new和delete运算符用于动态分配和撤销内存的运算符 new用法: 1.     开辟单变量地址空间 1)new int;  //开辟一个存放数组的存储空间 ...

  5. 清除目录下的SVN信息

    今天需要迁移一个版本库中的子目录到新的版本库中,以为不需要保留日志信息,所以只需拿最新的代码提交就可以. 对于清除目录下的SVN信息,在网上找一些方法,并实践执行了下: 在linux下 删除这些目录是 ...

  6. android 解析XML方式(三)

    上一节中,我们使用SAX方式解析xml文档, SAX方式是基于事件驱动的.当然android的事件机制是基于回调函数的.在这一节中,我们用另外一种方式解析xml文档,这种方式也是基于事件驱动的,与SA ...

  7. jquery中判断是否按下回车enter键

    <script>   function sendsubmit()   {   $("#userLoginForm").submit();   return false; ...

  8. java调用dll文件中的类型转换

    char *转String   (env)->NewStringUTF("the content you want to type in"); char *转jbyteArr ...

  9. struts2学习笔记(4)——数据类型转换

    回过头来看昨天的那个例子. 在昨天的例子中,只转换了一个Point类,如果想转换多个Point类怎么办呢?在昨天的例子上面做一个小的修改. 首先在input.jsp页面中修改几个输入框. <s: ...

  10. cojs EX_香蕉 题解报告

    这道题目是香蕉的加强版 当m=100w时矩阵会很大,而且又有多组询问,所以这道题用原来香蕉的程序会T 所以我们需要更好点的做法 我们考虑优化我们的状态 首先考虑这道题的隐藏性质,考虑不合法的情况 那么 ...