Fixed bugs for key maintanance codes in groupers (after being moved out of the aggregators).  

git-svn-id: https://hyracks.googlecode.com/svn/branches/aggregators_dev_next@1024 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-dataflow-std/src/main/java/edu/uci/ics/hyracks/dataflow/std/group/HashSpillableTableFactory.java b/hyracks-dataflow-std/src/main/java/edu/uci/ics/hyracks/dataflow/std/group/HashSpillableTableFactory.java
index 7d1ecd2..b0e092d 100644
--- a/hyracks-dataflow-std/src/main/java/edu/uci/ics/hyracks/dataflow/std/group/HashSpillableTableFactory.java
+++ b/hyracks-dataflow-std/src/main/java/edu/uci/ics/hyracks/dataflow/std/group/HashSpillableTableFactory.java
@@ -222,6 +222,10 @@
 
                     stateTupleBuilder.reset();
 
+                    for (int k = 0; k < keyFields.length; k++) {
+                        stateTupleBuilder.addField(accessor, tIndex, keyFields[k]);
+                    }
+                    
                     aggregator.init(stateTupleBuilder, accessor, tIndex, aggregateState);
                     if (!stateAppender.appendSkipEmptyField(stateTupleBuilder.getFieldEndOffsets(),
                             stateTupleBuilder.getByteArray(), 0, stateTupleBuilder.getSize())) {
diff --git a/hyracks-dataflow-std/src/main/java/edu/uci/ics/hyracks/dataflow/std/group/PreclusteredGroupWriter.java b/hyracks-dataflow-std/src/main/java/edu/uci/ics/hyracks/dataflow/std/group/PreclusteredGroupWriter.java
index 7e4baac..89955c0 100644
--- a/hyracks-dataflow-std/src/main/java/edu/uci/ics/hyracks/dataflow/std/group/PreclusteredGroupWriter.java
+++ b/hyracks-dataflow-std/src/main/java/edu/uci/ics/hyracks/dataflow/std/group/PreclusteredGroupWriter.java
@@ -77,7 +77,7 @@
 
                 tupleBuilder.reset();
                 for (int j = 0; j < groupFields.length; j++) {
-                    tupleBuilder.addField(inFrameAccessor, i, j);
+                    tupleBuilder.addField(inFrameAccessor, i, groupFields[j]);
                 }
                 aggregator.init(tupleBuilder, inFrameAccessor, i, aggregateState);
 
@@ -102,7 +102,7 @@
 
             tupleBuilder.reset();
             for (int j = 0; j < groupFields.length; j++) {
-                tupleBuilder.addField(currTupleAccessor, currTupleIndex, j);
+                tupleBuilder.addField(currTupleAccessor, currTupleIndex, groupFields[j]);
             }
             aggregator.init(tupleBuilder, currTupleAccessor, currTupleIndex, aggregateState);
         } else {
@@ -115,7 +115,7 @@
 
         tupleBuilder.reset();
         for (int j = 0; j < groupFields.length; j++) {
-            tupleBuilder.addField(lastTupleAccessor, lastTupleIndex, j);
+            tupleBuilder.addField(lastTupleAccessor, lastTupleIndex, groupFields[j]);
         }
         aggregator.outputFinalResult(tupleBuilder, lastTupleAccessor, lastTupleIndex, aggregateState);