1. 程式人生 > >mapreduce中reduce中的叠代器只能調用一次!

mapreduce中reduce中的叠代器只能調用一次!

new resultset row reducer style prot category nds 重復

親測,只能調用一次,如果想想在一次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中的叠代器只能調用一次!