【问题标题】:map reduce chaining not executed properly映射减少链接未正确执行
【发布时间】:2013-08-18 18:11:09
【问题描述】:

你好,我发现 map reduce 链接有点问题。我必须形成这样的链

ma​​pper->reducer->mapper

从我的第一个映射器到减速器的流程一直很好,这个减速器的输出数据不会正确地进入下一个映射器。这是我尝试过的一个简单的代码示例

这是我的第一个映射器

public void map(LongWritable key, Text value,
        OutputCollector<Text, IntWritable> outputCollector, Reporter reporter)
        throws IOException {

    String maxSalary = value.toString().split(",")[4]; 

    outputCollector.collect(new Text("max salary"),new IntWritable(Integer.parseInt(maxSalary)));

}

这是我的减速器

public void reduce(Text key, Iterator<IntWritable> values,
            OutputCollector<Text, IntWritable> outputCollector, Reporter reporter)
            throws IOException {
        int maxSalary = Integer.MIN_VALUE;

        while(values.hasNext()){

            maxSalary = Math.max(maxSalary, values.next().get());
        }
        outputCollector.collect(key, new IntWritable(maxSalary));

    }

这是我的下一个简单映射器

public void map(Text key, IntWritable value,
            OutputCollector<Text, IntWritable> outputCollector, Reporter reporter)
            throws IOException {

        System.out.println(value.toString());
    }

这是我运行该作业的主要课程

JobConf jobConf = new JobConf(jobrunner.class);
jobConf.setJobName("Chaining");

FileInputFormat.setInputPaths(jobConf, new Path("hdfs://localhost:9000/employee_data.txt"));
FileOutputFormat.setOutputPath(jobConf,new Path("hdfs://localhost:9000/chain9.txt"));

JobConf conf1 = new JobConf(false);

ChainMapper.addMapper(jobConf,chainmap.class,LongWritable.class,Text.class,Text.class,IntWritable.class,true,conf1);

JobConf conf2 = new JobConf(false);

ChainReducer.setReducer(jobConf, chainreduce.class,Text.class,IntWritable.class,Text.class,IntWritable.class,true,conf2);

JobConf conf3 = new JobConf(false);

ChainMapper.addMapper(jobConf, nextchainmap.class, Text.class,IntWritable.class,Text.class,IntWritable.class,true,conf3);


JobClient.runJob(jobConf);

我将在我的减速器中获得最高员工工资,这必须传递给下一个映射器,在那里它会找到具有最大工资值的员工记录,我如何在下一个映射器中实现这一点?有什么想法吗?

【问题讨论】:

    标签: hadoop mapreduce bigdata


    【解决方案1】:

    要链接您的第二个映射器,您需要调用 ChainReducer.addMapper(...) 而不是 ChainMapper.addMapper(...)

    【讨论】:

    • 谢谢,现在在下一个映射器中我得到了所需的值,现在在下一个映射器中我必须根据减速器的值再次处理文件的记录,即我从减速器,基于这个值,我应该得到最高工资的员工的记录..对此有什么帮助吗?
    • 您可能应该针对其他问题提出其他问题。同时,如果它解决了您的第一个问题,请接受我的回答:)
    猜你喜欢
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-13
    • 2022-01-25
    • 2020-08-02
    • 1970-01-01
    • 2020-11-18
    相关资源
    最近更新 更多