码迷,mamicode.com
首页 > 其他好文 > 详细

mapreduce中reduce中的迭代器只能调用一次!

时间:2017-05-27 00:40:56      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:res   cep   rabl   key   csdn   protected   result   xtend   category   

亲测,只能调用一次,如果想想在一次reduce重复使用迭代器中的数据,得先取出来放在list中然后在从list中取出来!!多次读取reduce函数中迭代器的数据

 

  public static class FindFriendReducer extends Reducer<Text, AllInfoBean, AllInfoBean, NullWritable>
  {
    protected void reduce(Text Keyin, Iterable<AllInfoBean> values, Reducer<Text, AllInfoBean, AllInfoBean, NullWritable>.Context context)
      throws IOException, InterruptedException
    {
      AllInfoBean allInfoBean = new AllInfoBean();
      allInfoBean.setPid(Keyin.toString());
      for (AllInfoBean bean : values) {
        if (bean.getOderid() != 0)
          continue;
        allInfoBean.setPname(bean.getPname());
        allInfoBean.setCategory_id(bean.getCategory_id());
        allInfoBean.setPrice(bean.getPrice());
      }

      for (AllInfoBean bean : values)
      {
        context.write(bean, NullWritable.get());
      }
    }
  }

这样是取不出来数据的!!

就 象jdbc 的resultset一样只能取一次

mapreduce中reduce中的迭代器只能调用一次!

标签:res   cep   rabl   key   csdn   protected   result   xtend   category   

原文地址:http://www.cnblogs.com/rocky-AGE-24/p/6910797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!