日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Mapreduce设置多路径输入输出

發布時間:2023/12/19 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Mapreduce设置多路径输入输出 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉載請注明:http://www.cnblogs.com/demievil/p/4058279.html

我的github博客:http://demievil.github.io/

最近寫Mapreduce程序時,想用到多路徑輸入,一次輸入多個文件夾下的數據。并且希望輸出路徑也可以區分,修改輸出文件的名稱。查了相關資料,已實現。

  • 多路徑輸入

設置Mapreduce的輸入是HDFS上多個文件夾下的數據,在main函數下稍作配置即可,示例代碼如下:

public static void main(String[] args) throws Exception { String ioPath[] = {"hdfs://10.1.2.3:8020/user/me/input/folder1","hdfs://10.1.2.3:8020/user/me/input/folder2","hdfs://10.1.2.3:8020/user/me/output"};Configuration conf = new Configuration();conf.set("fs.defaultFS", "hdfs://10.1.2.3:8020");conf.set("mapreduce.jobtracker.address", "10.1.2.3:8021");Job job = Job.getInstance(conf, "Job-Name"); job.setJarByClass(TestMain.class);job.setReducerClass(TestReducer.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(Text.class);FileSystem fs = FileSystem.get(conf);fs.delete(new Path(ioPath[2]),true);MultipleInputs.addInputPath(job, new Path(ioPath[0]), TextInputFormat.class, TagUrlMapper.class);MultipleInputs.addInputPath(job, new Path(ioPath[1]), TextInputFormat.class, TagUrlMapper.class);FileOutputFormat.setOutputPath(job, new Path(ioPath[2]));System.exit(job.waitForCompletion(true) ? 0 : 1);}

使用MultipleInputs.addInputPath()方法添加輸入路徑,輸入類型和Mapper類。

  • 多路徑輸出

在reducer中配置多路徑輸出及輸出文件名的開頭,示例代碼:

public class TestReducer extends Reducer<Text, Text, Text, Text> {private MultipleOutputs<Text, Text> mos;@Overrideprotected void setup(Context context) throws IOException, InterruptedException {super.setup(context);mos = new MultipleOutputs<Text, Text>(context);}@Overrideprotected void cleanup(Context context) throws IOException, InterruptedException {super.cleanup(context);mos.close();} @Overridepublic void reduce(Text key, Iterable<Text> values,Context context)throws IOException, InterruptedException {while(values.iterator().hasNext()){tag = values.iterator().next();if (......){mos.write(key, new Text("taged"), "taged/taged");}else{mos.write(key, new Text("untaged"), "untaged/untaged");}} }

使用MultipleOutputs類來控制輸出路徑。重寫Reducer的setup()和cleanup()方法,如示例代碼所示。

輸出路徑示例如下:

?

我的github博客:http://demievil.github.io/

轉載于:https://www.cnblogs.com/kodyan/p/4058279.html

總結

以上是生活随笔為你收集整理的Mapreduce设置多路径输入输出的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。