Mutual Friends MapReduce Application
Contents
Motivation
Finding mutual friends is a compelling MapReduce App and has a nice write up on the web.
Background
Be sure to complete the [[Set_Intersector_Assignment|SetIntersector<E>] warmup before starting this exercise.
Code To Investigate
Account
AccountId
SetIntersector<E>
class SetIntersector<E>
Code To Implement
MutualFriendsMapper
class: | MutualFriendsMapper.java | |
methods: | map | |
package: | mapreduce.apps.friends.exercise | |
source folder: | student/src/main/java |
method: public void map(Account account, BiConsumer<OrderedPair<AccountId>, Set<AccountId>> keyValuePairConsumer)
(sequential implementation only)
The only method you will need to alter is the map method. In this method, you will need to map every combination of the account holder to their friends. In order to do this, create ordered pairs of the given account’s ID and the IDs of the account holder’s friends. For each ordered pair, you feed the pair along with the full set of IDs of the account holder's friends into the keyValuePairConsumer.
Hint: check out the methods in the Account class for help.
MutualFriendsReducer
class: | MutualFriendsClassicReducer.java | |
methods: | reduce | |
package: | mapreduce.apps.friends.exercise | |
source folder: | student/src/main/java |
method: public Set<AccountId> reduce(List<Set<AccountId>> container)
(sequential implementation only)
SetIntersector can be used to calculate the set intersection. Invoke accept(set)
for each set in the <container> parameter, then invoke currentIntersection()
to get the result.
Testing Your Solution
Correctness
class: | _MutualFriendsTestSuite.java | |
package: | mapreduce | |
source folder: | testing/src/test/java |