【问题标题】:Hadoop M/R jobs chaining does not work with no exceptionHadoop M/R 作业链无一例外地不起作用
【发布时间】:2013-10-29 23:08:46
【问题描述】:

我正在尝试使用以下代码在 hadoop 中链接两个连续的 M/R 作业。基本上,在第一份工作完成后,我会做另一份工作,使用第一份工作的输出作为输入。但是该代码不会为第二个作业生成输出,也没有引发任何异常。大家能帮我看看哪里有问题吗?我很感激。

public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    String[] otherArgs = new GenericOptionsParser(conf, args)
            .getRemainingArgs();
    if (otherArgs.length != 3) {
        System.err.println("Usage: jobStats <in> <out> <job>");
        System.exit(2);
    }


    conf.set("job", otherArgs[2]);
    Job job = new Job(conf, "job count");
    job.setJarByClass(jobStats.class);
    job.setMapperClass(jobMapper.class);
    job.setCombinerClass(jobReducer.class);
    job.setReducerClass(jobReducer.class);

    job.setMapOutputKeyClass(Text.class);        
    job.setMapOutputValueClass(IntWritable.class);           
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
    FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));

    boolean completionStatus1 = job.waitForCompletion(true);
    if (completionStatus1 == true)
    {
        Job job2 = new Job(conf, "job year ranking");
        job2.setJarByClass(jobStats.class);
        job2.setPartitionerClass(ChainedPartitioner.class);
        job2.setGroupingComparatorClass(CompKeyGroupingComparator.class);
        job2.setSortComparatorClass(CompKeyComparator.class);

        job2.setMapperClass(ChainedMapper.class);
        job2.setReducerClass(ChainedReducer.class);
        job2.setPartitionerClass(ChainedPartitioner.class);
        job2.setMapOutputKeyClass(CompositeKey.class);
        job2.setMapOutputValueClass(IntWritable.class);
        job2.setOutputKeyClass(Text.class);
        job2.setOutputValueClass(IntWritable.class);

        Path outPath = new Path(otherArgs[1] + "part-r-00000"); // this is the hard-coded output of first job
        FileSystem fs = FileSystem.get(conf);
        if (fs.exists(outPath))
        {
            FileInputFormat.addInputPath(job2, outPath);
            FileOutputFormat.setOutputPath(job2, new Path("/user/tony/output/today"));

            boolean completionStatus2 = job2.waitForCompletion(true);
            if (completionStatus2 == true)
            {
                fs.delete(outPath, true);
                System.exit(0);
            }
            else System.exit(1);
        }
        else System.exit(1);
    }
}

【问题讨论】:

  • 程序的退出代码是什么?
  • 如果作业成功完成返回0,否则返回1
  • 你需要确保你的最终 reducer 真的有东西要写

标签: hadoop mapreduce


【解决方案1】:

ChainedMapper 和 ChainedReducer 类用于在单个 Map Reduce 作业中将多个映射器串在一起。类似于 M1-M2-M3-R-M4-M5。

在您的情况下,您希望连续运行两个完整的 map reduce 作业。只需指定第二份工作的真实地图即可。

【讨论】:

  • 我的理解是ChainedMapper/Reducer对我不起作用,因为我有两个reducer需要被chained,而ChainedMapper/Reducer类只允许一个reducer,对吧?
  • 没错。你应该连续运行两个工作,就像你正在做的那样。但是您为 OP 中的第二个作业提供的映射器是一个链式映射器,其中包含 0 个组件映射器。
  • 我的第二个映射器刚刚命名为ChainedMapper.java,哦,这可能是与系统ChainedMapper的冲突,对吧?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多