Skip to content

Commit b809043

Browse files
peel off special case for 1 dimensional groupby (#7777)
1 parent 7c695e9 commit b809043

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/groupby/DictionaryBasedGroupKeyGenerator.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ public void generateKeysForBlock(TransformBlock transformBlock, int[] groupKeys)
172172
BlockValSet blockValueSet = transformBlock.getBlockValueSet(_groupByExpressions[i]);
173173
_singleValueDictIds[i] = blockValueSet.getDictionaryIdsSV();
174174
}
175-
176175
_rawKeyHolder.processSingleValue(transformBlock.getNumDocs(), groupKeys);
177176
}
178177

@@ -253,12 +252,29 @@ private interface RawKeyHolder {
253252
}
254253

255254
private class ArrayBasedHolder implements RawKeyHolder {
256-
// TODO: using bitmap might better
257255
private final boolean[] _flags = new boolean[_globalGroupIdUpperBound];
258256
private int _numKeys = 0;
259257

260258
@Override
261259
public void processSingleValue(int numDocs, int[] outGroupIds) {
260+
if (_numGroupByExpressions == 1) {
261+
processSingleValue(numDocs, _singleValueDictIds[0], outGroupIds);
262+
} else {
263+
processSingleValueGeneric(numDocs, outGroupIds);
264+
}
265+
}
266+
267+
private void processSingleValue(int numDocs, int[] dictIds, int[] outGroupIds) {
268+
System.arraycopy(dictIds, 0, outGroupIds, 0, numDocs);
269+
for (int i = 0; i < numDocs; i++) {
270+
if (!_flags[outGroupIds[i]]) {
271+
_numKeys++;
272+
_flags[outGroupIds[i]] = true;
273+
}
274+
}
275+
}
276+
277+
private void processSingleValueGeneric(int numDocs, int[] outGroupIds) {
262278
for (int i = 0; i < numDocs; i++) {
263279
int groupId = 0;
264280
for (int j = _numGroupByExpressions - 1; j >= 0; j--) {
@@ -377,6 +393,20 @@ public IntMapBasedHolder(IntGroupIdMap groupIdMap) {
377393

378394
@Override
379395
public void processSingleValue(int numDocs, int[] outGroupIds) {
396+
if (_numGroupByExpressions == 1) {
397+
processSingleValue(numDocs, _singleValueDictIds[0], outGroupIds);
398+
} else {
399+
processSingleValueGeneric(numDocs, outGroupIds);
400+
}
401+
}
402+
403+
private void processSingleValue(int numDocs, int[] dictIds, int[] outGroupIds) {
404+
for (int i = 0; i < numDocs; i++) {
405+
outGroupIds[i] = _groupIdMap.getGroupId(dictIds[i], _globalGroupIdUpperBound);
406+
}
407+
}
408+
409+
private void processSingleValueGeneric(int numDocs, int[] outGroupIds) {
380410
for (int i = 0; i < numDocs; i++) {
381411
int rawKey = 0;
382412
for (int j = _numGroupByExpressions - 1; j >= 0; j--) {
@@ -612,7 +642,8 @@ public void processMultiValue(int numDocs, int[][] outGroupIds) {
612642
private int getGroupId(long rawKey) {
613643
int numGroups = _groupIdMap.size();
614644
if (numGroups < _globalGroupIdUpperBound) {
615-
return _groupIdMap.computeIfAbsent(rawKey, k -> numGroups);
645+
int id = _groupIdMap.putIfAbsent(rawKey, numGroups);
646+
return id == INVALID_ID ? numGroups : id;
616647
} else {
617648
return _groupIdMap.get(rawKey);
618649
}

0 commit comments

Comments
 (0)