Java 未调用Hadoop map()函数
我的map()函数在代码执行期间似乎根本没有被调用,我不明白为什么。下面是我的工作课Java 未调用Hadoop map()函数,java,hadoop,hdfs,Java,Hadoop,Hdfs,我的map()函数在代码执行期间似乎根本没有被调用,我不明白为什么。下面是我的工作课 public class MyHadoopJob extends Configured implements Tool{ static class MyMapper extends Mapper<LongWritable, Text, LongWritable, Text>{ public MyMapper(){ System.out.println("Mapper in
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;
}
}
公共类MyHadoopJob扩展配置的实现工具{
静态类MyMapper扩展了Mapper{
公共MyMapper(){
System.out.println(“Mapper init!”);
}
@凌驾
受保护的无效映射(可长写键、文本值、,
org.apache.hadoop.mapreduce.Mapper.Context)
抛出java.io.IOException、InterruptedException{
System.out.println(“MAP!”);
context.getCounter(“mygroup”、“jeff”).increment(1);
编写(键、值);
};
}
@凌驾
公共int运行(字符串[]字符串)引发异常{
配置conf=MYOBJ.getHadoopConf();
这是setConf(conf);
Job Job=新作业(conf,“MyJob”);
setJarByClass(MyHadoopJob.class);
setMapperClass(MyMapper.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
setMapOutputKeyClass(LongWritable.class);
job.setMapOutputValueClass(Text.class);
setInputPath(作业,新路径(字符串[0]);
setOutputPath(作业,新路径(字符串[1]);
job.waitForCompletion(true);
对于(int i=0;i<10;i++){
log.info(“Progress->”+job.mapProgress());
睡眠(15000);
}
返回0;
}
}
如果您能帮我弄清楚map()类或类初始化为何从未被调用,我将不胜感激。您似乎正在使用
System.out.println
语句调试Hadoop作业
这种方法的问题是,println
语句不会进入控制台。他们去工作日志。这就是为什么在控制台中看不到“Mapper init!”
您需要查看作业日志
引用一位伟人的话:
访问日志的简单方法是
>单击已完成的
作业->单击地图或减少任务->单击任务编号->任务
日志->标准日志
运行作业时您看到了什么?作业是否完成?