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
friend1reduce
extends
reducer
//a,d,c,e,f,h
for(
int i =
0; i < list.
size()
-1; i++)}
}}public
static
void
main
(string[
] args)
throws exception
}
public
class
friend2
}static
class
friend2reducer
extends
reducer
v.set(list.
tostring()
);context.
write
(key, v);}
}public
static
void
main
(string[
] args)
throws exception
}
結果
a和b的共同好友是: [e, c]a和d的共同好友是: [e]
a和e的共同好友是: [d, c, b]
… …
hadoop求共同好友案例
4.1 需求分析 以下是qq的好友列表資料,冒號前是乙個使用者,冒號後是該使用者的所有好友 資料中的好友關係是單向的 a b,c,d,f,e,o b a,c,e,k c a,b,d,e,i d a,e,f,l e b,c,d,m,l f a,b,c,d,e,o,m g a,c,d,e,f h a,c...
mysql共同好友 Spark 實現共同好友
核心 如下 object sprk import org.apache.spark.sql.sparksession def main args array string unit logger.getlogger org setlevel level.off logger.getlogger ak...
使用hive求共同好友
乙個mapreduce的經典題目 求共同好友,目前網上還沒有人用hive實現,我來用hive算一下。一 資料準備 create table friends people string,friends string insert into table friends people,friends va...