数据格式:
hadoop hello
hdfs world
tom cat
cat dog
hello world
每一行代表一个好友对,具体的思路是将所有数据倒置
map 阶段hadoop hello ==> hadoop hello | hello hadoop
reduce阶段,由于键相同的已经合并,在合并的数组中任何两个人都有可能是好友
代码如下:
qqMapper.java
package com.qq;
import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class qqMapper extends Mapper<LongWritable, Text, Text, Text>{
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException{
String line = value.toString();
String[] ss = line.split("\t");
context.write(new Tex