int buckNum = 0;
if (bucketEval != null && bucketEval.length != 0) {
buckNum = computeBucketNumber(vrg, rowIndex, conf.getNumBuckets());
cachedKeys[0][buckColIdxInKey] = new IntWritable(buckNum);
}
HiveKey firstKey = toHiveKey(cachedKeys[0], tag, null);
int distKeyLength = firstKey.getDistKeyLength();
// Add first distinct expression, if any.
if (numDistinctExprs > 0) {
populateCachedDistinctKeys(vrg, rowIndex, 0);
firstKey = toHiveKey(cachedKeys[0], tag, distKeyLength);
}
if (useTopN) {
reducerHash.tryStoreVectorizedKey(firstKey, batchIndex);
} else {
// No TopN, just forward the first key and all others.
int hashCode = 0;
if (bucketEval != null && bucketEval.length != 0) {
hashCode = computeHashCode(vrg, rowIndex, buckNum);
} else {
hashCode = computeHashCode(vrg, rowIndex);
}
firstKey.setHashCode(hashCode);
BytesWritable value = makeValueWritable(vrg, rowIndex);
collect(firstKey, value);
forwardExtraDistinctRows(vrg, rowIndex, hashCode, value, distKeyLength, tag, 0);
}
}
if (!useTopN) return; // All done.
// If we use topN, we have called tryStore on every key now. We can process the results.
for (int batchIndex = 0 ; batchIndex < vrg.size; ++batchIndex) {
int result = reducerHash.getVectorizedBatchResult(batchIndex);
if (result == TopNHash.EXCLUDE) continue;
int rowIndex = batchIndex;
if (vrg.selectedInUse) {
rowIndex = vrg.selected[batchIndex];
}
// Compute value and hashcode - we'd either store or forward them.
int hashCode = computeHashCode(vrg, rowIndex);
BytesWritable value = makeValueWritable(vrg, rowIndex);
int distKeyLength = -1;
if (result == TopNHash.FORWARD) {
HiveKey firstKey = reducerHash.getVectorizedKeyToForward(batchIndex);
firstKey.setHashCode(hashCode);
distKeyLength = firstKey.getDistKeyLength();
collect(firstKey, value);
} else {
reducerHash.storeValue(result, value, hashCode, true);
distKeyLength = reducerHash.getVectorizedKeyDistLength(batchIndex);
}