Java – use MapReduce to find the average of numbers

I've been trying to write some code to find the average of numbers using MapReduce

I try to use global counters to achieve my goal, but I can't set the counter value in my mapper's map method, and I can't retrieve the counter value in reducer's reduce method

Do I have to use global counters in the map (for example, by using the incrcounter (key, amount) of the reporter provided)? Or would you suggest any different logic to get the average of some numbers?

Solution

The logic is very simple:

Note that if the combiner class is set to the same class as the reducer, this logic will not work

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
分享
二维码
< <上一篇
下一篇>>