MapReduce多文件输出
2015-07-11 11:05
337 查看
public static class MyReduce extends Reducer<Text,Text,Text,Text>{ public static Text keyout = new Text(); public static Text valout = new Text(); private MultipleOutputs<Text,Text> mos; <pre name="code" class="java"> <span style="color:#FF0000;">//使用输入的上下文创建MultipleOutputs 实例</span> public void setup(Context context) throws IOException, InterruptedException{ mos = new MultipleOutputs(context); } public void reduce(Text key,Iterable<Text> values,Context context) throws IOException, InterruptedException{ int tmplen = 0; String tmpval = ""; for(Text val:values){ int tmpvallen = val.toString().length(); if(tmpvallen >tmplen){ tmplen = tmpvallen; tmpval = val.toString(); } } keyout.set(key); valout.set(tmpval); <span style="color:#FF0000;"> //输出格式===key.toString().split(",").length+"" -m - nnnnn</span> mos.write(keyout, valout, key.toString().split(",").length+""); //context.write(keyout, valout); }//一定要close(),否则完全没有输出 public void cleanup(Context context) throws IOException, InterruptedException{ mos.close();}}
MultipleOutputs可以在Mapper或Reducer中使用,使用时需要在map()或reduce()中的setup()方法里面创建MultipleOutputs实例,还需要在cleanup()中关闭输出。
相关文章推荐
- tar
- html 捕捉 enter事件
- POJ 2243 Knight Moves A*
- 视频摘要与检索
- java构造器 笔记
- 身份证规则验证java代码方法 非正则匹配
- FZU1894 志愿者选拔(队列) ~TLE
- UI2_IOS坐标系
- navicat工具 快捷键 -- Mysql
- SharedPreferences总结
- java抽象类 笔记
- 对于移动端浏览器touch事件的研究总结(4)判断手指滑动方向
- Android imageView图片按比例缩放
- [leedcode 46] Permutations
- java接口 笔记
- struct、union、enum and sizeof
- javascript 学习笔记(权威指南)
- liferay初体验
- Docker-2.容器有关
- 养生保健常识