【问题标题】:Get max salary employee name using hadoop map reduce使用hadoop map reduce获取最高工资员工姓名
【发布时间】:2013-08-16 07:45:04
【问题描述】:

我对 M/R 程序非常陌生。我在 HDFS 中有一个文件,其中包含此结构中的数据

EmpId,EmpName,Dept,Salary,

1231,userName1,Dept1,5000
1232,userName2,Dept2,6000
1233,userName3,Dept3,7000
.
.
.........................

现在我想找到薪水最高的员工的姓名

我已经写了一个 map reduce 来找到最高薪水。在我的 mapper 类中,我发出了这样的输出

output.collect("最大值",员工工资);

在减速器中,我找到了键“最大值”的最大值。现在我想在映射器中使用这个值并找到获得最高薪水的员工的姓名。我如何发送减速器输出到映射器作为输入?这是完成我的任务的好方法吗?还有其他建议吗?

【问题讨论】:

    标签: hadoop mapreduce hadoop-partitioning


    【解决方案1】:

    我会让地图发出最高工资的完整元组。为此,创建一个实现Writable 接口(@98​​7654321@)的类(用于值)。也许TupleWritable 适合您的需求(不是很复杂)。

    由于您将在每个映射中发出 1 个值,因此网络不是问题,并且似乎可以在 reducer 中接收所有元组数据。您的减速器只需要从“最大值”值中过滤掉顶部。

    对于更复杂的问题,您将不得不考虑链接作业 (http://developer.yahoo.com/hadoop/tutorial/module4.html#chaining)

    【讨论】:

    • 好建议,我已经实施了,而且很成功
    【解决方案2】:

    我可以建议以下解决方案

    1. Find the max salary using your mapreduce job
    
    2. Read the max salary from hdfs (it should be in the file in output folder of your job)
    
    3. Save the max salary two configuration, say `configuration.set("max.salary", maxSalary);`
    
    4. Create new mapper-only job. The mapper of this job should read maxSalary value from the configuration in the setup method and filter out employers with salary equal to the maxSalary in map method. Pass your data to this job.
    

    结果,你会

    附:但作为更好的方法,我建议您使用HIVEPIG 来完成此类任务,因为如果它们不涉及复杂的数学/业务逻辑,在高级仪器中实现它们会更容易,例如蜂巢和猪(以及其他一些)。

    【讨论】:

    • 如何设置从reducer到配置对象的最高工资
    猜你喜欢
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多