hadoop - map reduce 链接未正确执行

标签 hadoop mapreduce bigdata

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

映射器->reducer->映射器

从我的第一个 mapper 到 reducer 的流程一直很好,这个 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)));

}

这是我的 reducer

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

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

最佳答案

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

关于hadoop - map reduce 链接未正确执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18302233/

相关文章:

hadoop - 使用哈希Mod采样数据帧

java - Hadoop 未在 Windows 7 上启动任何数据节点

java - HIPI API : does it process 1 image per map task?

search - Google Freebase 搜索 API 替代方案?

Python Pandas : Convert 2, 000,000 DataFrame 行到二进制矩阵 (pd.get_dummies()) 没有内存错误?

hadoop - 处理 PIG 脚本中的 fs(hadoop shell)命令错误

hadoop - Sqoop-如何使用伪列进行拆分

hadoop - Hbase MapReduce程序中如何自动生成RowId

hadoop - 即使所有守护进程都在使用hadoop,连接也会被拒绝,

hadoop - 为什么运行 1TB teragen 时没有 reducer ?