解读:MR多路径输入
生活随笔
收集整理的這篇文章主要介紹了
解读:MR多路径输入
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
對于在一個MR-Job中使用多路徑作為輸入文件,一般有三種方法:
1).多次調用,加載不同路徑:
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;//輸入路徑in01 in02 String in01 = "hdfs://RS5-112:9000/cs01/path01"; String in02 = "hdfs://RS5-112:9000/cs02/path02";//多次調用addInputPath()方法 FileInputFormat.addInputPath(job,new Path(in0)); FileInputFormat.addInputPath(job,new Path(in1));2).一次調用,同時加載多路徑(字符串用逗號隔開):
//這種方式的第二個參數只能是:將路徑以逗號拼接的字符串 FileInputFormat.addInputPaths(job,"hdfs://RS5-112:9000/cs01/path1,hdfs://RS5-112:9000/cs02/path2");3).使用MultipleInputs類的方法
addInputPath(Job job, Path path,Class<? extends InputFormat> inputFormatClass); addInputPath(Job job, Path path,Class<? extends InputFormat> inputFormatClass,Class<? extends Mapper> mapperClass);MultipleInputs類的強大之處在于不僅可以多次調用addInputPath()方法加載路徑,而且可以根據路徑的不同指定不同的輸入格式,更有甚者還可以根據輸入格式的不同指定不同的Mapper函數進行處理。詳見 MR案例:倒排索引 && MultipleInputs?和 MR案例:CombineFileInputFormat
DEMO1:
MultipleInputs.addInputPath(job, new Path("hdfs://RS5-112:9000/cs01/path01"), TextInputFormat.class); MultipleInputs.addInputPath(job, new Path("hdfs://RS5-112:9000/cs02/path2"), KeyValueInputFormat.class);DEMO2:
MultipleInputs.addInputPath(job, new Path("hdfs://RS5-112:9000/cs01/path01"), TextInputFormat.class,Mapper01.class); MultipleInputs.addInputPath(job, new Path("hdfs://RS5-112:9000/cs02/path2"), KeyValueInputFormat.class,Mapper02.class);?
轉載于:https://www.cnblogs.com/skyl/p/4753703.html
總結
以上是生活随笔為你收集整理的解读:MR多路径输入的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: redis系列
- 下一篇: Unity开发NGUI代码实现Scrol