xiangfu0 commented on code in PR #19834:
URL: https://github.com/apache/pinot/pull/19834#discussion_r4289844956
##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/groupby/MultiKeysGroupIdGenerator.java:
##########
@@ -47,19 +56,27 @@ public MultiKeysGroupIdGenerator(ColumnDataType[] keyTypes,
int numKeyColumns,
_keyToIdMaps[i] = ValueToIdMapFactory.get(keyTypes[i].toDataType());
}
_numGroupsLimit = numGroupsLimit;
+ _currentKey = new FixedIntArray(new int[numKeyColumns]);
}
@Override
public int getGroupId(Object key) {
Object[] keyValues = (Object[]) key;
- int numKeyColumns = keyValues.length;
- int[] keyIds = new int[numKeyColumns];
- if (_groupIdMap.size() < _numGroupsLimit) {
+ int numKeyColumns = _keyToIdMaps.length;
+ FixedIntArray currentKey = _currentKey;
+ int[] keyIds = currentKey.elements();
+ int numGroups = _groupIdMap.size();
+ if (numGroups < _numGroupsLimit) {
for (int i = 0; i < numKeyColumns; i++) {
Object keyValue = keyValues[i];
keyIds[i] = keyValue != null ? _keyToIdMaps[i].put(keyValue) : NULL_ID;
}
- return _groupIdMap.computeIfAbsent(new FixedIntArray(keyIds),
_groupIdGenerator);
+ int groupId = _groupIdMap.computeIfAbsent(currentKey, _groupIdGenerator);
+ if (_groupIdMap.size() != numGroups) {
+ // A new group is created and the map holds a reference to the current
key, so allocate a new one
+ _currentKey = new FixedIntArray(new int[numKeyColumns]);
Review Comment:
Small readability thought (non-blocking): detecting the insert via the
`size()` change is clever but a touch implicit. Since `_groupIdGenerator`
already returns the new group id equal to the pre-insert size, an equivalent
and slightly more direct check is `if (groupId == numGroups)`. Totally optional
— the current code is correct as written.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]