Java – find friends of all users: how to implement Hadoop MapReduce?

Say I entered the following:

(1,2)(2,1)(1,3)(3,4)(4,1)

The output is expected to be as follows:

(1,(2,3,4)) -> (1,3) //second index is total friend #
(2,(1,4)) -> (2,3)
(3,2))   -> (3,2)
(4,2))   -> (4,2)

I know how to do this in Java using HashSet But I don't know how to use MapReduce model Can anyone throw out any ideas or sample code on this issue? I would appreciate it

————————————————– ———————————-

This is my naive solution: 1 mapper, 2 reducers Mapper will organize input (1,2), 1), 3);

Organize output as

*(1, HashSet's & lt 2 –), HashSet's & lt 1 is halogen), HashSet's & 3; 1 +), (3, the & lt 1 of HashSet is halogen;) *

Reducer1:

Take mapper's output as input and output:

*(1, HashSet < 2,3 >), HashSet < 1 >) and (2, HashSet < 1 >)*

Reducer2:

Take the output of reducer1 as input and output:

*(1,1) and (2,1)*

This is just my naive solution I'm not sure if this can be done with Hadoop code

Solution

I think there should be a simple way to solve this problem

Mapper Input: (1,1)

Only two records need to be issued for each pair, as follows:

Mapper Output/ Reducer Input:

Key => Value
1 => 2
2 => 1
2 => 1
1 => 2
1 => 3
3 => 1
3 => 2
2 => 3
2 => 4
4 => 2
4 => 1
1 => 1

In terms of reducer, you will get four different groups, as shown below:

Reducer Output:

Key => Values
1 => [2,4]
2 => [1,4]
3 => [1,2]
4 => [1,2]

You can now format the results as needed

The above is the Java collected by programming house for you - find friends of all users: how to use Hadoop MapReduce? I hope this article can help you solve Java - find friends of all users: how to use Hadoop MapReduce? Program development problems encountered.

If you think the content of the programming home website is good, you are welcome to recommend the programming home website to programmers and friends.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>