首页 > 代码库 > mapreduce中reduce中的迭代器只能调用一次!

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

亲测,只能调用一次,如果想想在一次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中的迭代器只能调用一次!