-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMostCommon.java
More file actions
47 lines (42 loc) · 1.67 KB
/
MostCommon.java
File metadata and controls
47 lines (42 loc) · 1.67 KB
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
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Partitioner;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;
public class MostCommon {
public static class MapperClass extends Mapper<Text, Text, OurLong, Text> {
public void map(Text key, Text value, Context context) throws IOException, InterruptedException {
// that-compl 10
context.write(new OurLong(Long.parseLong(value.toString())), key);
}
}
public static class ReducerClass extends Reducer<OurLong, Text, Text,Text> {
private int count100;
private int count1000;
private int size;
public void setup(Context context){
count100 = 100;
count1000 = 0;
size = 1000;
}
public void reduce(OurLong key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
if (count1000 < size) {
for (Text value : values) {
if (count100 > 0) {
count100--;
} else if (count1000 < size) {
context.write(value, new Text(key.toString() + " " + count1000));
count1000++;
}
}
}
}
public void cleanup(Context context) { }
}
public static class PartitionerClass extends Partitioner<OurLong, Text> {
public int getPartition(OurLong key, Text value, int numPartitions) {
return (key.hashCode() & Integer.MAX_VALUE) % numPartitions;
}
}
}