Reducer类阅读
2015-09-01 20:53
417 查看
Reducer类中主要有setup,run,reduce,cleanup这几个函数。
/**
* Called once at the start of the task.
*/
protected void setup(Context context
) throws IOException, InterruptedException {
// NOTHING
}
从上边的程序可以看出在执行的时候先执行setup函数,最后执行cleanup函数。
/**
* Called once at the start of the task.
*/
protected void setup(Context context
) throws IOException, InterruptedException {
// NOTHING
}
/** * This method is called once for each key. Most applications will define * their reduce class by overriding this method. The default implementation * is an identity function. */ @SuppressWarnings("unchecked") protected void reduce(KEYIN key, Iterable<VALUEIN> values, Context context ) throws IOException, InterruptedException { for(VALUEIN value: values) { context.write((KEYOUT) key, (VALUEOUT) value); } }
/** * Called once at the end of the task. */ protected void cleanup(Context context ) throws IOException, InterruptedException { // NOTHING }在用户的应用程序中调用到reducer时,会直接调用reducer里面的run函数,其代码如下:
/* * control how the reduce task works. */ @SuppressWarnings("unchecked") public void run(Context context) throws IOException, InterruptedException { setup(context); while (context.nextKey()) { reduce(context.getCurrentKey(), context.getValues(), context); // If a back up store is used, reset it ((ReduceContext.ValueIterator) (context.getValues().iterator())).resetBackupStore(); } cleanup(context); } }
从上边的程序可以看出在执行的时候先执行setup函数,最后执行cleanup函数。
相关文章推荐
- 编程常见英语单词小结
- 华为机试:名字的漂亮度
- ARM汇编指令:adr和ldr的前因后果
- _beginthreadex和_beginthread区别,调用_endthread不会析构局部变量??
- spring的@ModelAttribute作用
- 字符串同构的最小表示方法
- javascript 之闭包
- 找出单链表的倒数第K个(从1开始计数)结点的值
- Hibernate知识点汇总
- OpenCV2:Mat
- 31 Next Permutation
- 杭电OJ-2032_杨辉三角
- jquery中的多条件选择,相对选择和层次选择
- UGUI基本控件(二)
- Android问题集(二)——TextView在点击时显示不同颜色,Button点击效果
- ImageJ二次开发学习纪录之初步体会
- 反转一个链表并输出各个结点的值
- oracle查看表占用磁盘空间
- 省市联动
- ajax异步请求