2011-12-28 64 views
1

我想從Map-Reduce程序中的多個目錄中讀取多個文件。 我曾試圖給出的文件名中的主要方法:如何在Map-Reduce中從多個目錄中讀取多個文件

FileInputFormat.setInputPaths(conf,new Path("hdfs://localhost:54310/user/test/")); 
FileInputFormat.setInputPaths(conf,new Path("hdfs://localhost:54310/Test/test1/")); 

但僅從一個文件中讀取。

我該怎麼做才能讀取多個文件?

請提出解決方案。

謝謝。

回答

0
Follow the below steps for passsing multiple input files from different direcories.Just driver code changes.Follow the below driver code. 
CODE: 
public int run(String[] args) throws Exception { 
     Configuration conf=new Configuration(); 
     Job job=Job.getInstance(conf, "MultipleDirectoryAsInput"); 

     job.setMapperClass(Map1Class.class); 
     job.setMapperClass(Map2Class.class); 
     job.setReducerClass(ReducerClass.class);   
     job.setJarByClass(DriverClass.class);  
     job.setMapOutputKeyClass(Text.class); 
     job.setMapOutputValueClass(IntWritable.class);  
     job.setOutputKeyClass(Text.class); 
     job.setOutputValueClass(NullWritable.class);   
     //FileInputFormat.setInputPaths(job, new Path(args[0]));   
     MultipleInputs.addInputPath(job, new Path(args[0]),TextInputFormat.class,Map1Class.class); 
     MultipleInputs.addInputPath(job, new Path(args[1]), TextInputFormat.class, Map2Class.class);    
     FileOutputFormat.setOutputPath(job, new Path(args[2])); 
     return job.waitForCompletion(true)?0:1;  
    } 
相關問題