bziobrowski commented on code in PR #14662:
URL: https://github.com/apache/pinot/pull/14662#discussion_r1886632963
##########
pinot-core/src/main/java/org/apache/pinot/core/data/table/IndexedTable.java:
##########
@@ -157,11 +166,44 @@ public void finish(boolean sort, boolean
storeFinalResult) {
for (int i = 0; i < numAggregationFunctions; i++) {
columnDataTypes[i + _numKeyColumns] =
_aggregationFunctions[i].getFinalResultColumnType();
}
- for (Record record : _topRecords) {
- Object[] values = record.getValues();
- for (int i = 0; i < numAggregationFunctions; i++) {
- int colId = i + _numKeyColumns;
- values[colId] =
_aggregationFunctions[i].extractFinalResult(values[colId]);
+ if (_numThreadsForFinalReduce > 1) {
+ // Multi-threaded final reduce
+ try {
+ List<Record> topRecordsList = new ArrayList<>(_topRecords);
+ int chunkSize = (topRecordsList.size() + _numThreadsForFinalReduce -
1) / _numThreadsForFinalReduce;
+ List<Future<Void>> futures = new ArrayList<>();
+ for (int threadId = 0; threadId < _numThreadsForFinalReduce;
threadId++) {
+ int startIdx = threadId * chunkSize;
+ int endIdx = Math.min(startIdx + chunkSize, topRecordsList.size());
+
+ if (startIdx < endIdx) {
+ // Submit a task for processing a chunk of values
+ futures.add(EXECUTOR_SERVICE.submit(() -> {
+ for (int recordIdx = startIdx; recordIdx < endIdx;
recordIdx++) {
+ Object[] values = topRecordsList.get(recordIdx).getValues();
+ for (int i = 0; i < numAggregationFunctions; i++) {
+ int colId = i + _numKeyColumns;
+ values[colId] =
_aggregationFunctions[i].extractFinalResult(values[colId]);
+ }
+ }
+ return null;
+ }));
+ }
+ }
+ // Wait for all tasks to complete
+ for (Future<Void> future : futures) {
+ future.get();
+ }
Review Comment:
Would it be worth cancelling running threads if one of the throws exception
instead of letting them run until completion ?
--
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]