分享

Hadoop mapper类的阅读

lzw 2013-11-30 15:26:13 发表于 其它 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 26 84878
在Hadoop的mapper类中,有4个主要的函数,分别是:setup,clearup,map,run。代码如下:
  1. protected void setup(Context context) throws IOException, InterruptedException {
  2. // NOTHING
  3. }
  4. protected void map(KEYIN key, VALUEIN value,
  5.                      Context context) throws IOException, InterruptedException {
  6. context.write((KEYOUT) key, (VALUEOUT) value);
  7. }
  8. protected void cleanup(Context context) throws IOException, InterruptedException {
  9. // NOTHING
  10. }
  11. public void run(Context context) throws IOException, InterruptedException {
  12.     setup(context);
  13.     while (context.nextKeyValue()) {
  14.       map(context.getCurrentKey(), context.getCurrentValue(), context);
  15.     }
  16.     cleanup(context);
  17.   }
  18. }
复制代码
由上面的代码,我们可以了解到,当调用到map时,通常会先执行一个setup函数,最后会执行一个cleanup函数。而默认情况下,这两个函数的内容都是nothing。因此,当map方法不符合应用要求时,可以试着通过增加setup和cleanup的内容来满足应用的需求。

加入qq群(号码:39327136),讨论云技术,获取最新资讯资源等

欢迎加入about云群9037177932227315139327136 ,云计算爱好者群,亦可关注about云腾讯认证空间||关注本站微信

已有(26)人评论

跳转到指定楼层
yizuoming 发表于 2014-9-3 07:49:08
谢谢分享,学习了
回复

使用道具 举报

maizhu 发表于 2014-10-3 20:44:03
谢谢分享,学习了
回复

使用道具 举报

InSight 发表于 2014-10-7 20:23:33
感谢分享,学习了。
回复

使用道具 举报

monkey_d 发表于 2014-12-23 11:26:38
学习了,谢谢分享
回复

使用道具 举报

tang 发表于 2015-3-6 14:25:23
学习了,多谢分享
回复

使用道具 举报

狂奔啦蜗牛 发表于 2015-3-28 16:54:49
说明看的不是很明白
回复

使用道具 举报

Minimumy 发表于 2015-3-30 10:05:26
多谢分享!学习了!
回复

使用道具 举报

fdfdggg 发表于 2015-7-7 10:59:56
正在看,谢谢
回复

使用道具 举报

123下一页
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条