去重

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.qr.mr.removeduplicate;

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 java.io.IOException;

/**
* http://www.aboutyun.com/thread-7041-1-1.html
*/
public class RemoveDuplicate {

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 {//todo
line = value;
context.write(line,new Text(""));
}
}

public static class Reduce extends Reducer<Text,Text,Text,Text>{
public void reduce(Text key,Iterable<Text> values,Context context)
throws IOException, InterruptedException {//todo
context.write(key,new Text(""));
}
}

public static void main(String[] args)
throws IOException, ClassNotFoundException, InterruptedException {//todo
Configuration conf = new Configuration();
Job job = Job.getInstance(conf,"RemoveDuplicate");//todo
job.setJarByClass(RemoveDuplicate.class);

job.setMapperClass(Map.class);
job.setCombinerClass(Reduce.class);//todo
job.setReducerClass(Reduce.class);

job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);

FileInputFormat.addInputPath(job,new Path("/Users/lifei/qrproject/hiveudf/src/main/java/com/qr/mr/removeduplicate/in"));
FileOutputFormat.setOutputPath(job,new Path("/Users/lifei/qrproject/hiveudf/src/main/java/com/qr/mr/removeduplicate/out"));

System.exit(job.waitForCompletion(true) ? 0: 1);
}
}