数据格式:
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

该博客介绍如何利用MapReduce处理好友关系数据,通过将数据倒置并在Reduce阶段合并,找出可能的好友对。Map阶段将好友对拆分为键值对,Reduce阶段使用HashSet检查每个用户的朋友集合,如果集合大小超过1,则输出所有可能的好友组合。
最低0.47元/天 解锁文章
4445

被折叠的 条评论
为什么被折叠?



