2011-12-28 3 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;  
    } 
관련 문제