解读:MR多路径输入
生活随笔
收集整理的這篇文章主要介紹了
解读:MR多路径输入
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
對于在一個(gè)MR-Job中使用多路徑作為輸入文件,一般有三種方法:
1).多次調(diào)用,加載不同路徑:
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";//多次調(diào)用addInputPath()方法 FileInputFormat.addInputPath(job,new Path(in0)); FileInputFormat.addInputPath(job,new Path(in1));2).一次調(diào)用,同時(shí)加載多路徑(字符串用逗號(hào)隔開):
//這種方式的第二個(gè)參數(shù)只能是:將路徑以逗號(hào)拼接的字符串 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類的強(qiáng)大之處在于不僅可以多次調(diào)用addInputPath()方法加載路徑,而且可以根據(jù)路徑的不同指定不同的輸入格式,更有甚者還可以根據(jù)輸入格式的不同指定不同的Mapper函數(shù)進(jìn)行處理。詳見 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);?
轉(zhuǎn)載于:https://www.cnblogs.com/skyl/p/4753703.html
總結(jié)
以上是生活随笔為你收集整理的解读:MR多路径输入的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: redis系列
- 下一篇: Unity开发NGUI代码实现Scrol