2014-01-10 42 views
0

我的代碼執行期間,我的map()函數似乎沒有被調用,我不明白爲什麼。下面是我工作的類...沒有調用Hadoop map()函數

public class MyHadoopJob extends Configured implements Tool{ 

static class MyMapper extends Mapper<LongWritable, Text, LongWritable, Text>{ 

    public MyMapper(){ 
     System.out.println("Mapper init!"); 
    } 

    @Override 
    protected void map(LongWritable key, Text value, 
         org.apache.hadoop.mapreduce.Mapper<LongWritable, Text, LongWritable, Text>.Context context) 
      throws java.io.IOException, InterruptedException { 
     System.out.println("MAP!"); 
     context.getCounter("mygroup", "jeff").increment(1); 
     context.write(key, value); 
    }; 
} 

@Override 
public int run(String[] strings) throws Exception { 

    Configuration conf = MYOBJ.getHadoopConf(); 
    this.setConf(conf); 

    Job job = new Job(conf, "MyJob"); 
    job.setJarByClass(MyHadoopJob.class); 
    job.setMapperClass(MyMapper.class); 
    job.setOutputKeyClass(Text.class); 
    job.setOutputValueClass(Text.class); 
    job.setMapOutputKeyClass(LongWritable.class); 
    job.setMapOutputValueClass(Text.class); 

    FileInputFormat.setInputPaths(job, new Path(strings[0])); 
    FileOutputFormat.setOutputPath(job, new Path(strings[1])); 

    job.waitForCompletion(true); 

    for(int i = 0; i < 10; i++){ 
     log.info("Progress -> " + job.mapProgress()); 
     Thread.sleep(15000); 
    } 

    return 0; 
    } 

} 

我真的很感激一些幫助搞清楚爲什麼地圖()類或確實類的初始化永遠不會叫什麼名字?

+0

當你完成作業時你看到了什麼? –

回答

0

您似乎在使用System.out.println語句來調試Hadoop作業。

這種方法的問題是,println語句不會去您的控制檯。他們去找工作日誌。這就是爲什麼你沒有看到「Mapper init!」在你的控制檯。

您需要查看作業日誌。

引述一個偉大的人(這answer):

訪問日誌容易的方法是 http://example.com:50030/jobtracker.jsp->點擊完成 求職>點擊地圖或減少任務 - >點擊tasknumber - >任務 logs-> stdout日誌。