friends.txt:
A:B,C,D,F,E,O
B:A,C,E,K
C:F,A,D,I
D:A,E,F,L
需求:求每两个人的共同好友(A和B,A和C…)
… …
一、
/**
* A:B,C,D,F,E,O
* B:A,C,E,K
* 好友列表作为k:B-->A C-->A D-->A
* A-->B C-->B E-->B
* 将matask端的value(本人)添加到list集合 集合中任意两人的共同好友即为maptask的key
* 再写一个MR聚合
*
*/
public class Friend1 {
static class Friend1Mapper extends Mapper<LongWritable, Text,Text,Text>{
Text k = new Text();
Text v = new Text();
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
//A:B,C,D,F,E,O
String[] split = value.toString().split(":");
String uid = split[0];
String[] fs = split[1].split(",");
v.set(uid);
for (String f : fs) {
k.set(f);
context.write