简体   繁体   English

(Hadoop):运行mapreduce作业时reduce方法未执行/未调用

[英](Hadoop): reduce method is not getting executed/called while running mapreduce job

I am facing a problem in executing one my mapreduce job. 我在执行我的mapreduce工作时遇到问题。 As part of my map reduce task I am using mapreduce joins which includes multiple map methods and single reducer method. 作为我的map reduce任务的一部分,我正在使用mapreduce联接,其中包括多个map方法和单个reducer方法。

Both of my map methods are getting executed, but my reducer is not getting executed/called from my driver class. 我的两个map方法都正在执行,但是我的reducer并没有从驱动程序类执行/调用。

Because of this, the final output is having only the data that was collected during my map phase. 因此,最终输出仅包含在我的地图阶段收集的数据。

Am i using the wrong input and output values during the reduce phase? 我在减速阶段是否使用了错误的输入和输出值? Is there any input and output mismatching between map and reduce phase? 映射和归约相位之间是否存在任何输入和输出不匹配?

Help me in this regard. 在这方面帮助我。

Here is my code.. 这是我的代码。

public class CompareInputTest extends Configured implements Tool  {

public static class FirstFileInputMapperTest extends Mapper<LongWritable,Text,Text,Text>{


    private Text word = new Text();
    private String keyData,data,sourceTag = "S1$";

    public void map(LongWritable key,Text value,Context context) throws IOException, InterruptedException{

        String[] values = value.toString().split(";");
        keyData = values[1];
        data = values[2];

        context.write(new Text(keyData), new Text(data+sourceTag));


    }
}

public static class SecondFileInputMapperTest extends Mapper<LongWritable,Text,Text,Text>{
    private Text word = new Text();
    private String keyData,data,sourceTag = "S2$";
    public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException{

        String[] values = value.toString().split(";");
        keyData = values[1];
        data = values[2];


        context.write(new Text(keyData), new Text(data+sourceTag));

    }

              }

public static class CounterReducerTest extends Reducer
 {
    private String status1, status2;

    public void reduce(Text key, Iterable<Text> values, Context context)
       throws IOException, InterruptedException {
        System.out.println("in reducer");

        for(Text value:values)
           {
           String splitVals[] = currValue.split("$");
        System.out.println("in reducer");
       /*
        * identifying the record source that corresponds to a commonkey and
        * parses the values accordingly
       */
      if (splitVals[0].equals("S1")) {
         status1 = splitVals[1] != null ? splitVals[1].trim(): "status1";
      } else if (splitVals[0].equals("S2")) {
          // getting the file2 and using the same to obtain the Message
          status2 = splitVals[2] != null ? splitVals[2].trim(): "status2";
      }
           }

        context.write(key, new Text(status1+"$$$"));
    }






 public static void main(String[] args) throws Exception {


     int res = ToolRunner.run(new Configuration(), new CompareInputTest(),
             args);
System.exit(res);

     }

} }

public int run(String[] args) throws Exception {
    Configuration conf = new Configuration();
     Job job = new Job(conf, "count");
     job.setJarByClass(CompareInputTest.class);
     MultipleInputs.addInputPath(job,new Path(args[0]),TextInputFormat.class,FirstFileInputMapperTest.class);
     MultipleInputs.addInputPath(job,new Path(args[1]),TextInputFormat.class,SecondFileInputMapperTest.class);
     job.setReducerClass(CounterReducerTest.class);
     //job.setNumReduceTasks(1);
     job.setMapOutputKeyClass(Text.class);
     job.setMapOutputValueClass(Text.class);
     job.setOutputKeyClass(Text.class);
     job.setOutputValueClass(Text.class);




     FileOutputFormat.setOutputPath(job, new Path(args[2]));



     return (job.waitForCompletion(true) ? 0 : 1);

}

} }

Just check the prototype of the reducer class. 只需检查reducer类的原型即可。

extends Reducer<KEY, VALUE, KEY,VALUE>

In your case since the reducer gets as input and emits as output Text, change the definition from 在您的情况下,由于reducer作为输入而作为输出Text发出,因此请从

public static class CounterReducerTest extends Reducer

to

public static class CounterReducerTest extends Reducer<Text,Text,Text,Text>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM