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 4b76d74..5b4c7c3 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 @@ -458,10 +458,18 @@ private void prepareBatchAggregationBufferSets(VectorizedRowBatch batch) throws // to bump its internal version. aggregationBatchInfo.startBatch(); + if (batch.size == 0) { + return; + } + // We now have to probe the global hash and find-or-allocate // the aggregation buffers to use for each key present in the batch VectorHashKeyWrapper[] keyWrappers = keyWrappersBatch.getVectorHashKeyWrappers(); - for (int i=0; i < batch.size; ++i) { + + final int n = keyExpressions.length == 0 ? 1 : batch.size; + // note - the row mapping is not relevant when aggregationBatchInfo::getDistinctBufferSetCount() == 1 + + for (int i=0; i < n; ++i) { VectorHashKeyWrapper kw = keyWrappers[i]; VectorAggregationBufferRow aggregationBuffer = mapKeysAggregationBuffers.get(kw); if (null == aggregationBuffer) { diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java index 63cdf94..b235a3e 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hive.ql.exec.vector; +import org.apache.hadoop.hive.ql.exec.vector.VectorHashKeyWrapper.EmptyVectorHashKeyWrapper; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriter; import org.apache.hadoop.hive.ql.metadata.HiveException; @@ -89,6 +90,11 @@ public int getKeysFixedSize() { */ public void evaluateBatch(VectorizedRowBatch batch) throws HiveException { + if (keyCount == 0) { + // all keywrappers must be EmptyVectorHashKeyWrapper + return; + } + for(int i=0;i