【问题标题】:Hadoop second reducer not being called when chaining two jobs链接两个作业时未调用 Hadoop 第二个减速器
【发布时间】:2016-05-02 17:30:07
【问题描述】:

我有一个 hadoop 程序,我想在其中链接两个作业,以便输入 -> mapper1 -> reducer1 -> mapper2 -> reducer2 -> 输出。前半部分工作正常,我得到了正确的中间输出。问题在于第二份工作。特别是,我相信在第二份工作中,映射器由于某种原因没有调用正确的减速器,因为我得到了类型不匹配。 这是我设置作业的主要代码:

    //JOB 1
    Path input1 = new Path(otherArgs.get(0));
    Path output1 =new Path("/tempBinaryPath");

    Job job1 = Job.getInstance(conf);
        job1.setJarByClass(BinaryPathRefined.class);
        job1.setJobName("BinaryPathR1");

    FileInputFormat.addInputPath(job1, input1);
    FileOutputFormat.setOutputPath(job1, output1);

    job1.setMapperClass(MyMapper.class);
    //job.setCombinerClass(MyReducer.class);
    job1.setReducerClass(MyReducer.class);

    job1.setInputFormatClass(TextInputFormat.class);

    job1.setOutputKeyClass(Text.class);
    job1.setOutputValueClass(Text.class);

    job1.waitForCompletion(true);


    // JOB 2
    Path input2 = new Path("/tempBinaryPath/part-r-00000");
    Path output2 =new Path(otherArgs.get(1));

    Job job2 = Job.getInstance(conf2);
        job2.setJarByClass(BinaryPathRefined.class);
        job2.setJobName("BinaryPathR2");

    FileInputFormat.addInputPath(job2, input2);
    FileOutputFormat.setOutputPath(job2, output2);

    job2.setMapperClass(MyMapper2.class);
    //job.setCombinerClass(MyReducer.class);
    job2.setReducerClass(MyReducer2.class);

    job2.setInputFormatClass(TextInputFormat.class);

    job2.setOutputKeyClass(Text.class);
    job2.setOutputValueClass(Text.class);

    job2.waitForCompletion(true);

映射器和化简器的形式为:

public static class MyMapper extends Mapper<LongWritable, Text, Text, Text>{
...
}

public static class MyReducer extends Reducer<Text, Text, Text, Text>{
...
}

public static class MyMapper2 extends Mapper<LongWritable, Text, Text, IntWritable>{
...
}

public static class MyReducer2 extends Reducer<Text, IntWritable, Text, Text>{
...
}

第一个作业运行良好,而第二个我收到错误:

Type mismatch in value from map: expected org.apache.hadoop.io.Text, received org.apache.hadoop.io.IntWritable

有什么想法吗?

【问题讨论】:

    标签: java hadoop mapreduce


    【解决方案1】:

    当您仅调用 setOutputKeyClasssetOutputValueClass 时,Hadoop 将假定 Mapper 和 Reducer 具有相同的输出类型。在您的情况下,您应该明确设置 Mapper 产生的输出类型:

    job2.setOutputKeyClass(Text.class);
    job2.setMapOutputValueClass(IntWritable.class);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-30
      • 2013-12-10
      • 2018-12-13
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      • 2015-01-11
      • 1970-01-01
      相关资源
      最近更新 更多