-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitReducer.java
More file actions
33 lines (23 loc) · 806 Bytes
/
Copy pathInitReducer.java
File metadata and controls
33 lines (23 loc) · 806 Bytes
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
package edu.upenn.nets212.hw3;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class InitReducer extends Reducer<Text, Text, Text, Text >{
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
String follows = ""; //following string
for (Text s : values) {
if (!s.toString().equals("")) { //if the person has friends
follows = follows + "," + s;
}
}
if (follows.length() > 1) { //if the person has friends
follows = follows.substring(1);
follows = "1!" + follows;
} else {
follows = "1!";
}
Text val = new Text(follows);
context.write(key, val); //user, rank, and adjacency list
}
}