title: manipulating iterator in mapreduce
body: <p>I am trying to find the sum of any given points using hadoop, The issue I am having is on getting all values from a given key in a single reducer. It looks like this.</p>
  
  <p>Reducer:</p>
  
  <pre><code> public static class Reduce extends MapReduceBase implements
          Reducer&lt;Text, IntWritable, Text, DoubleWritable&gt; {
  
      public void reduce(Text key, Iterator&lt;IntWritable&gt; values,
              OutputCollector&lt;Text, DoubleWritable&gt; output, Reporter reporter)
              throws IOException {
          Text word = new Text();
  
          Iterator&lt;IntWritable&gt; tr = values;
          IntWritable v;
          while (tr.hasNext()) {
               v = tr.next();
  
              Iterator&lt;IntWritable&gt; td = values;
              while (td.hasNext()) {
  
                  IntWritable u = td.next();
                  double sum = u+v;
                  word.set( u + " + " + v);
                  output.collect(word, new DoubleWritable(sum));
              }
          }
      }
  }
  </code></pre>
  
  <p>And I am trying to create two copies of the Iterator variable so that I can go through all the values of the second iterator while I get a single value from the previous Iterator( Two while loops above) but the two iterators hold the same value all the time.</p>
  
  <p>I am not sure if this is the right way to do it.</p>