2014-11-14 3 views
0

이것이 아주 기본적인 질문이지만 내가 실수를하고있는 곳을 찾을 수는 없습니다. 내 Reducer가 드라이버 코드에서 호출되지 않습니다. 누구든지 나를 도울 수 있으면 크게 감사 할 것입니다. 오랜 시간 후Hadoop : 감속기가 호출되지 않음

내 드라이버 코드

package com.mycompany.myorg; 

import java.io.IOException; 

import org.apache.hadoop.conf.Configuration; 
import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.io.IntWritable; 
import org.apache.hadoop.io.Text; 
import org.apache.hadoop.mapreduce.Job; 
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 
import org.apache.hadoop.util.GenericOptionsParser; 

public class carsDriver { 

    public static void main(String args[]) throws IOException, ClassNotFoundException, InterruptedException{ 

     Configuration conf = new Configuration(); 

     String[] otherArgs = new GenericOptionsParser(conf,args).getRemainingArgs(); 

     if(otherArgs.length != 2){ 
      System.err.println("specified input and output path is not correct"); 
      System.exit(-1); 
     } 

     // set up the job details 

     Job job = new Job(conf,"Cars Avg Fuel Economy"); 
     job.setJarByClass(carsDriver.class); 
     //job.setJobName("Cars Avg Fuel Economy"); 

     //setup the input and output paths for the MR job 
     FileInputFormat.setInputPaths(job, new Path(args[0])); 
     FileOutputFormat.setOutputPath(job, new Path(args[1])); 

     // setup of the Mapper, combiner and Reducer classes 
     job.setMapperClass(carsMapper.class); 
     job.setMapOutputKeyClass(Text.class); 
     job.setMapOutputValueClass(IntWritable.class); 

     //job.setCombinerClass(carsCombiner.class); 
     job.setReducerClass(carsReducer.class); 
     job.setOutputKeyClass(Text.class); 
     job.setOutputValueClass(IntWritable.class); 

     System.exit(job.waitForCompletion(true)?0:1);  
    } 

} 

매퍼 코드

package com.mycompany.myorg; 

import java.io.IOException; 

import org.apache.hadoop.io.IntWritable; 
import org.apache.hadoop.io.Text; 
import org.apache.hadoop.mapreduce.Mapper; 

public class carsMapper extends Mapper<Object, Text, Text, IntWritable> { 

    private Text mapkey = new Text(); 
    private final static IntWritable mapval = new IntWritable(1); 

    public void map(Object key, Text Value,Mapper<Object, Text, Text, IntWritable>.Context context ) throws IOException, InterruptedException{ 

     System.out.println("Running the Mapper"); 
     String items[] = Value.toString().split(","); 

     System.out.println(items[2]+" "+Integer.parseInt(items[23].toString())); 

     mapkey.set(items[2]); 
     mapval.set(Integer.parseInt(items[23].toString())); 

     context.write(mapkey, mapval); 

    } 
} 

감속기 코드

package com.mycompany.myorg; 

import java.io.IOException; 

import org.apache.hadoop.io.IntWritable; 
import org.apache.hadoop.io.Text; 
import org.apache.hadoop.mapreduce.Reducer; 

public class carsReducer extends Reducer<Text, IntWritable, Text, IntWritable> { 

    public void reducer(Text key, Iterable<IntWritable> value,Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException { 

     System.out.println("Reducer Code"); 
     Text redKey = new Text(); 
     IntWritable redVal = new IntWritable(); 


     redKey.set(key); 

     int sum=0; 
     int count=0; 
     for(IntWritable val: value){ 
      sum= sum +val.get(); 
      count= count + 1; 
     } 

     redVal.set((sum/count)); 

     context.write(redKey, redVal); 

    } 
} 
+0

전화가 걸리지 않았다고 확신 할 수 있습니까? 'syso' 문은 작업이 제출되는 콘솔에서 볼 수 없을 수도 있습니다. 'hadoop fs -ls'가 작업의 outputDirectory에 보여주는 것을 공유하십시오. – blackSmith

+0

매퍼에서 system.out 인쇄물을 추가했기 때문에 나는 그것에 대해 꽤 확신합니다. 그리고 그것은 작동하고 감속기에서 인쇄하지 않습니다. 또한 저는 감속기의 호출에 대해서도 논평하고 심지어 같은 출력을 시도했습니다. 출력은 키의 평균이어야하지만 그냥 매퍼의 결과입니다. – user2596892

답변

0

문제를 디버깅 나는 문제가 축소 무시 메서드를 발견했습니다.

가 나는 대신 감속기을 절감해야한다는 관찰
public void reduce 

public void reducer 

대신

을 사용했다.

관련 문제