diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupByOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupByOperator.java index 90748e9..a9dc32a 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupByOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupByOperator.java @@ -813,6 +813,12 @@ public void doProcessBatch(VectorizedRowBatch batch, boolean isFirstGroupingSet, if (first) { // Copy the group key to output batch now. We'll copy in the aggregates at the end of the group. first = false; + + // Evaluate the key expressions of just this first batch to get the correct key. + for (int i = 0; i < outputKeyLength; i++) { + keyExpressions[i].evaluate(batch); + } + groupKeyHelper.copyGroupKey(batch, outputBatch, buffer); } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupKeyHelper.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupKeyHelper.java index 0ff389e..64706ad 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupKeyHelper.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupKeyHelper.java @@ -32,6 +32,8 @@ */ public class VectorGroupKeyHelper extends VectorColumnSetInfo { + private int[] outputColumnNums; + public VectorGroupKeyHelper(int keyCount) { super(keyCount); } @@ -41,12 +43,14 @@ void init(VectorExpression[] keyExpressions) throws HiveException { // NOTE: To support pruning the grouping set id dummy key by VectorGroupbyOpeator MERGE_PARTIAL // case, we use the keyCount passed to the constructor and not keyExpressions.length. - // Inspect the output type of each key expression. + // Inspect the output type of each key expression. And, remember the output columns. + outputColumnNums = new int[keyCount]; for(int i=0; i < keyCount; ++i) { String typeName = VectorizationContext.mapTypeNameSynonyms(keyExpressions[i].getOutputType()); TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(typeName); Type columnVectorType = VectorizationContext.getColumnVectorTypeFromTypeInfo(typeInfo); addKey(columnVectorType); + outputColumnNums[i] = keyExpressions[i].getOutputColumn(); } finishAdding(); } @@ -61,9 +65,9 @@ void init(VectorExpression[] keyExpressions) throws HiveException { public void copyGroupKey(VectorizedRowBatch inputBatch, VectorizedRowBatch outputBatch, DataOutputBuffer buffer) throws HiveException { for(int i = 0; i< longIndices.length; ++i) { - int keyIndex = longIndices[i]; - LongColumnVector inputColumnVector = (LongColumnVector) inputBatch.cols[keyIndex]; - LongColumnVector outputColumnVector = (LongColumnVector) outputBatch.cols[keyIndex]; + final int columnIndex = outputColumnNums[longIndices[i]]; + LongColumnVector inputColumnVector = (LongColumnVector) inputBatch.cols[columnIndex]; + LongColumnVector outputColumnVector = (LongColumnVector) outputBatch.cols[columnIndex]; // This vectorized code pattern says: // If the input batch has no nulls at all (noNulls is true) OR @@ -87,9 +91,9 @@ public void copyGroupKey(VectorizedRowBatch inputBatch, VectorizedRowBatch outpu } } for(int i=0;i retPair = validateAggregationDescs(desc.getAggregators(), processingMode, hasKeys); if (!retPair.left) {