How to design the Key Value pairs for Mapreduce to find the maximum value in a set?

£可爱£侵袭症+ 提交于 2019-12-12 04:14:26

问题


I am beginner of MapReduce programmer. Can you help me design the key-value pairs for the following problem ?

Problem statement - Find the maximum value and print it along with the key

Input :

   Key       Value
   ABC       10
   TCA       13
   RTY       23
   FTY       45

The key on the left-hand side column will be unique.No duplicates allowed.

Output :

   FTY       45

Since 45 is the highest of all values, it has to be printed along with the key.

Can you help me in designing the map() and reduce() function? What will be the key-value pairs for both functions?


回答1:


In mapper, remember the greatest number

class Mapper {
   V maxV;
   K maxK;

   map(K, V, context) {
      if (V > maxV) { maxV = V; maxK = K; }
   }

   cleanup(context) {
      context.store(maxK, maxV)
   }
}

Do the same in reducer. Configure the job to have only 1 reducer.



来源:https://stackoverflow.com/questions/44681695/how-to-design-the-key-value-pairs-for-mapreduce-to-find-the-maximum-value-in-a-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!