2012-08-23 40 views
1

我提以下一個簡單的MAPR程序的驅動程序代碼輸出目錄中JobConf

import org.apache.hadoop.fs.Path; 
    import org.apache.hadoop.io.IntWritable; 
    import org.apache.hadoop.io.Text; 
    import org.apache.hadoop.mapred.JobClient; 
    import org.apache.hadoop.mapred.JobConf; 
    import org.apache.hadoop.mapreduce.Job; 
    import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 
    import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 

    @SuppressWarnings("deprecation") 
    public class CsvParserDriver { 
     @SuppressWarnings("deprecation") 
     public static void main(String[] args) throws Exception 
     { 
      if(args.length != 2) 
      { 
       System.out.println("usage: [input] [output]"); 
       System.exit(-1); 
      } 

      JobConf conf = new JobConf(CsvParserDriver.class); 
      Job job = new Job(conf); 
      conf.setJobName("CsvParserDriver"); 

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

      conf.setMapperClass(CsvParserMapper.class); 
      conf.setMapOutputKeyClass(IntWritable.class); 
      conf.setMapOutputValueClass(Text.class); 

      conf.setReducerClass(CsvParserReducer.class); 
      conf.setOutputKeyClass(Text.class); 
      conf.setOutputValueClass(Text.class); 

      conf.set("splitNode","NUM_AE"); 

      JobClient.runJob(conf); 
     } 
    } 

我使用下面的命令運行我的代碼沒有設置

hadoop jar CsvParser.jar CsvParserDriver /user/sritamd/TestData /user/sritamd/output 

(所有相應的罐子和在上面的命令創建目錄)

我得到錯誤作爲

Exception in thread "main" org.apache.hadoop.mapred.InvalidJobConfException: Output directory not set in JobConf. 

回答

1

您沒有像在apache-hadoop-tutorial中指定的那樣創建HDFS輸入和輸出目錄。

如果您要使用本地目錄file:///user/sritamd/TestData - 添加FS前綴。

0

我認爲你需要的輸入和輸出目錄設置的conf的代替工作我愛:

FileInputFormat.setInputPaths(conf, new Path(args[0])); 

FileOutputFormat.setOutputPath(conf, new Path(args[1])); 
0

試試這個

Configuration configuration = new Configuration(); 
Job job = new Job(configuration, "MyConfig"); 

然後

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

這可能是由舊API和新API造成的。

這是我的新的作業API來做配置。

第一步:輸入新的API的lib

import org.apache.hadoop.mapreduce.Job 

第二步:通過新的API工作做配置。

val job = Job.getInstance(conf) 
job.getConfiguration.set(TableOutputFormat.OUTPUT_TABLE, tableName) 
job.setOutputFormatClass(classOf[TableOutputFormat[Put]]) 

希望這可以幫助你。

+1

假設我想使用自定義記錄寫入器寫入其他數據庫(不是mysql,因爲記錄寫入器已經在hadoop中)那麼應該怎樣配置才能刪除此異常? – iec2011007

0

如果你正在標準模式下運行hadoop(沒有集羣)來測試你不需要在輸出路徑中有fs前綴的代碼。您可以初始化作業並設置路徑。下面的代碼應該工作(請確保您所選擇的職位(從org.apache.hadoop.mapreduce.Job)或JobConf org.apache.hadoop.mapred.JobConf)

 Job job = new Job(); 
     job.setJobName("Job Name"); 
     job.setJarByClass(MapReduceJob.class); 

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

     job.setMapperClass(MaxTemperatureMapper.class); 
     job.setReducerClass(MaxTemperatureReducer.class); 

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

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

我有同樣的問題,但固定它。我使用job.waitForCompletion(true)這會導致在使用saveAsNewAPIHadoopFile(...)時hbase上的火花崩潰。一個 因爲它使用的是舊的Hadoop API,而不是新的API的

0
  • 首先確保你的目錄不存在,你不應該等待你的工作。如果存在刪除它。
  • 第二次在Eclipse中運行您的代碼,如果它運行正常並給出ArrayOutofBounds警告。

否則,請檢查您插入的庫,確保插入所有CLIENT庫或檢查您的類是否在包中。

如果上述所有條件滿足您的工作將執行。