如何设计Mapreduce的键值对以在集合中找到最大值? [英] How to design the Key Value pairs for Mapreduce to find the maximum value in a set?

查看:256
本文介绍了如何设计Mapreduce的键值对以在集合中找到最大值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MapReduce程序员的初学者.您能帮我设计以下问题的键值对吗?

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

输入:

   Key       Value
   ABC       10
   TCA       13
   RTY       23
   FTY       45

左侧列的键是唯一的.不允许重复.

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

输出:

   FTY       45

由于45是所有值中的最高值,因此必须与键一起打印.

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

您可以帮助我设计map()和reduce()函数吗?这两个函数的键值对是什么?

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

推荐答案

在mapper中,记住最大的数字

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)
   }
}

在reducer中执行相同的操作.将作业配置为仅具有1个减速机.

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

这篇关于如何设计Mapreduce的键值对以在集合中找到最大值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆