Index: ql/src/java/org/apache/hadoop/hive/ql/exec/GroupByOperator.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/GroupByOperator.java (revision 738603) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/GroupByOperator.java (working copy) @@ -192,6 +192,7 @@ hashAggregations = new HashMap, UDAFEvaluator[]>(); hashAggr = true; keyPositionsSize = new ArrayList(); + aggrPositions = new ArrayList(); } // init objectInspectors @@ -326,11 +327,13 @@ // Go over all the aggregation classes and and get the size of the fields of fixed length. Keep track of the variable length // fields in these aggregation classes. for(int i=0; i < aggregationClasses.length; i++) { + fixedRowSize += javaObjectOverHead; Class agg = aggregationClasses[i]; - Field[] fArr = agg.getFields(); - for (Field f : fArr) - fixedRowSize += getSize(i, agg, f); + Field[] fArr = agg.getDeclaredFields(); + for (Field f : fArr) { + fixedRowSize += getSize(i, f.getType(), f); + } } } @@ -486,7 +489,7 @@ int numEntries = hashAggregations.size(); // The fixed size for the aggregation class is already known. Get the variable portion of the size every NUMROWSESTIMATESIZE rows. - if ((numEntries % NUMROWSESTIMATESIZE) == 0) { + if ((numEntriesHashTable == 0) || ((numEntries % NUMROWSESTIMATESIZE) == 0)) { for (Integer pos : keyPositionsSize) { Object key = newKeys.get(pos.intValue()); totalVariableSize += ((String)key).length(); @@ -511,6 +514,7 @@ } numEntriesVarSize++; + // Update the number of entries that can fit in the hash table numEntriesHashTable = (int)(maxHashTblMemory / (fixedRowSize + ((int)totalVariableSize/numEntriesVarSize))); LOG.trace("Hash Aggr: #hash table = " + numEntries + " #max in hash table = " + numEntriesHashTable);