码迷,mamicode.com
首页 > 其他好文 > 详细

Hadoop-4、Mapred数据去重

时间:2014-05-08 11:27:24      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   ext   

bubuko.com,布布扣
import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
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 DelRep {
    public static class Map extends Mapper<Object,Text,Text,Text>{
        private static Text line = new Text();
        public void map(Object key,Text value,Context context) throws IOException, InterruptedException{
            line = value;
            context.write(line, new Text(""));
        }
    }
    
    public static class Reduce extends Reducer<Text,Text,Text,Text>{
        public void reduce(Text key,Iterable<Text> value,Context context) throws IOException, InterruptedException{
            context.write(key, new Text(""));
        }
    }
    
    public static void main(String[] Args) throws IOException, ClassNotFoundException, InterruptedException{
        Configuration conf = new Configuration();
        conf.addResource(new Path("/usr/hadoop-1.0.3/conf/core-site.xml"));
        
        String[] otherArgs = new GenericOptionsParser(conf,Args).getRemainingArgs();
        
        Job job = new Job(conf,"DelRep");
        
        job.setJarByClass(DelRep.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(otherArgs[0]));
        FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
        
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
bubuko.com,布布扣

File1:

1
2
3
4
5
6
7
8
2006-6-9 a
2006-6-10 b
2006-6-11 c
2006-6-12 d
2006-6-13 a
2006-6-14 b
2006-6-15 c
2006-6-11 c

File2

1
2
3
4
5
6
7
8
2006-6-9 d
2006-6-10 a
2006-6-11 b
2006-6-12 d
2006-6-13 a
2006-6-14 c
2006-6-15 d
2006-6-11 c

结果:

1
2
3
4
5
6
7
8
9
10
11
12
2006-6-10 a
2006-6-10 b
2006-6-11 b
2006-6-11 c
2006-6-12 d
2006-6-13 a
2006-6-14 b
2006-6-14 c
2006-6-15 c
2006-6-15 d
2006-6-9 a 
2006-6-9 d 

  

Hadoop-4、Mapred数据去重,布布扣,bubuko.com

Hadoop-4、Mapred数据去重

标签:style   blog   class   code   java   ext   

原文地址:http://www.cnblogs.com/wn19910213/p/3714507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!