今天在测试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. 【转载】MySQL查询阻塞语句

    select r.trx_id waiting_trx_id, r.trx_mysql_thread_Id waiting_thread,        r.trx_query waiting_que ...

  2. python之类定义

    <python基础教程>第7章说python中的类定义: 1. 要么声明__metaclass__=type 2. 要么继承object. 但是直接定义下类, 也没报错: >> ...

  3. GDAL编译(转)

    一.简单的编译 1.使用VisualStudio IDE编译 首先进入GDAL的源代码目录,可以看到有几个sln为后缀的文件名,比如makegdal10.sln,makegdal80.sln,make ...

  4. VBS基础篇 - 条件语句

    经常地,当我们编写代码时,我们需要根据不同的判断执行不同操作,我们可以使用条件语句完成这个工作. If...Then...Else 在下面的情况中,您可以使用 If...Then...Else 语句: ...

  5. sql行转列和列转行(转)

    行列互转,是一个经常遇到的需求.实现的方法,有case when方式和2005之后的内置pivot和unpivot方法来实现. 在读了技术内幕那一节后,虽说这些解决方案早就用过了,却没有系统性的认识和 ...

  6. 【Leetcode】 - Single Number II

    Problem Discription: Suppose the array A has n items in which all of the numbers apear 3 times excep ...

  7. 修改tomcat 启动45秒

    当我们需要增加Tomcat的启动时间,修改方法如下:

  8. tangent space /handness

    normal tangent bitangent 三者互相垂直. 组成一个tangent space 表示一个点 对于原本位置的偏移(扰动) 考虑到这是为了 normalmap做出虚假的normal来 ...

  9. setDepthStencilState

    cgfx->hlsl StencilFunc={always,1,0xff}->setDepthStencilState(DepthState,0) StencilFunc={always ...

  10. Unity3D 问题流水总结

    一.error CS1612:Cannot modify a value type return value of `UnityEngine.SliderJoint2D.limits'. Consid ...