【问题标题】:Sending mapper output to different reducer将映射器输出发送到不同的减速器
【发布时间】:2014-07-02 23:49:55
【问题描述】:

我是 Hadoop 新手,现在我正在使用 java 映射器/缩减器代码。在工作时,我遇到了一个问题,我必须将映射器类的输出传递给两个不同的减速器类。如果可能的话。我们也可以从同一个映射器类发送两个不同的输出......谁能告诉我..

【问题讨论】:

    标签: java hadoop


    【解决方案1】:

    我一直在尝试做同样的事情。根据我的发现,我们不能将映射器输出发送到两个减速器。但是可以通过区分 reducer 中的任务来执行您想要在两个 reducer 中执行的任务。 reducer 可以根据一些关键标准选择任务。我必须警告你,我是 hadoop 新手,所以可能不是最好的答案。

    映射器将生成像这样的键 +-TASK_XXXX。然后reducer会调用不同的方法来处理TASK_XXXX

    认为最好在末尾加上 TASK_NAME 以确保有效分区。

    至于你的第二个问题,我相信你可以将多个输出从同一个映射器类发送到减速器。您可能对这篇文章感兴趣Can Hadoop mapper produce multiple keys in output?

    map 方法看起来像

        @Override
        protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
            //do stuff 1
            Text outKey1 = new Text(<Your_Original_Key>+"-TASK1");
            context.write(outKey, task1OutValues);
    
            //do stuff 2
            Text outKey2 = new Text(<Your_Original_Key>+"-TASK2");
            context.write(outKey, task2OutValues);
        }
    

    和reduce方法

        @Override
        protected void reduce(Text inkey, Iterable<Text> values, Reducer<Text, Text, Text, Text>.Context context) throws IOException, InterruptedException {
            String key = inKey.toString();
            if(inKey.matches(".*-TASK1$")) {
                processTask1(values);
            } else if(inKey.matches(".*-TASK2$")) {
                processTask2(values);
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-23
      • 1970-01-01
      • 2014-09-20
      相关资源
      最近更新 更多