2017-01-15 28 views
0

我試圖從IntelliJ內部運行Map-Reduce作業。這是我的亞軍代碼,IntelliJ內部的Mapreduce作業失敗

public class ViewCount extends Configured implements Tool{ 

    @Override 
    public int run(String[] args) throws Exception { 
     Configuration conf = this.getConf(); 


     Job job = Job.getInstance(conf); 
     job.setJobName("viewCount"); 
     job.setJarByClass(ViewCount.class); 

     job.setOutputKeyClass(Text.class); 
     job.setOutputValueClass(IntWritable.class); 

     job.setMapperClass(Map.class); 
     job.setReducerClass(Reduce.class); 

     Path inputFilePath = new Path(args[0]); 
     Path outputFilePath = new Path(args[1]); 

     FileInputFormat.addInputPath(job, inputFilePath); 
     FileOutputFormat.setOutputPath(job, outputFilePath); 

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

    } 

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

     int exitCode = ToolRunner.run(new ViewCount(), args); 
     System.exit(exitCode); 
    } 

該任務無法生成並顯示以下錯誤消息。

error: incompatible types: Job cannot be converted to JobConf 
     FileOutputFormat.setOutputPath(job, outputFilePath); 

Apached文檔表明該方法實際上是一個工作而不是一個JobConf,所以我做錯了什麼?

+2

這與IntelliJ無關 – Moira

+1

您可能正在混合映射減少1和2個API。檢查您從哪裏導入FileOutputFormat。舊的mapreduce(org.apache.hadoop.mapred.FileOutputFormat)接受JobConf,而新的(org.apache.hadoop.mapreduce.lib.output.FileOutputFormat)接受Job作爲參數。 – Amit

回答

0

看看類來自的包。您可能正在混合包,並且您需要根據您的Hadoop版本使用正確包中的TextInputFormat。如果您使用的是Hadoop版本2.x,那麼您需要導入與Hadoop版本1.x(具有映射包)相比的不同類(來自mapreduce包)