Jackie-Jiang commented on code in PR #14714:
URL: https://github.com/apache/pinot/pull/14714#discussion_r1919554209


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/combine/DistinctCombineOperator.java:
##########
@@ -19,26 +19,130 @@
 package org.apache.pinot.core.operator.combine;
 
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicReference;
 import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.AcquireReleaseColumnsSegmentOperator;
+import org.apache.pinot.core.operator.blocks.results.BaseResultsBlock;
 import org.apache.pinot.core.operator.blocks.results.DistinctResultsBlock;
-import 
org.apache.pinot.core.operator.combine.merger.DistinctResultsBlockMerger;
+import org.apache.pinot.core.operator.blocks.results.ExceptionResultsBlock;
+import org.apache.pinot.core.query.distinct.table.DistinctTable;
 import org.apache.pinot.core.query.request.context.QueryContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
  * Combine operator for distinct queries.
  */
 @SuppressWarnings("rawtypes")
 public class DistinctCombineOperator extends 
BaseSingleBlockCombineOperator<DistinctResultsBlock> {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DistinctCombineOperator.class);
   private static final String EXPLAIN_NAME = "COMBINE_DISTINCT";
 
+  private final AtomicReference<DistinctResultsBlock> _mergedResultsBlock = 
new AtomicReference<>();
+  private final AtomicReference<DistinctResultsBlock> _satisfiedResultsBlock = 
new AtomicReference<>();
+  private final CountDownLatch _latch;
+
   public DistinctCombineOperator(List<Operator> operators, QueryContext 
queryContext, ExecutorService executorService) {
-    super(new DistinctResultsBlockMerger(), operators, queryContext, 
executorService);
+    super(null, operators, queryContext, executorService);
+    _latch = new CountDownLatch(_numTasks);
   }
 
   @Override
   public String toExplainString() {
     return EXPLAIN_NAME;
   }
+
+  @Override
+  protected void processSegments() {
+    int operatorId;
+    while (_processingException.get() == null && (operatorId = 
_nextOperatorId.getAndIncrement()) < _numOperators) {
+      if (_satisfiedResultsBlock.get() != null) {
+        return;
+      }
+      Operator operator = _operators.get(operatorId);
+      DistinctResultsBlock resultsBlock;
+      try {
+        if (operator instanceof AcquireReleaseColumnsSegmentOperator) {
+          ((AcquireReleaseColumnsSegmentOperator) operator).acquire();
+        }
+        resultsBlock = (DistinctResultsBlock) operator.nextBlock();
+      } catch (RuntimeException e) {
+        throw wrapOperatorException(operator, e);
+      } finally {
+        if (operator instanceof AcquireReleaseColumnsSegmentOperator) {
+          ((AcquireReleaseColumnsSegmentOperator) operator).release();
+        }
+      }
+
+      // Use the atomic reference as the swap space to merge the results 
blocks. If the swap space is null, put the new
+      // results block in it. If the swap space is not null, take the results 
block from the swap space, and merge it
+      // with the new results block. Repeat this process until successfully 
put the new results block in the swap space.
+      // After all threads are done, the results block in the swap space is 
the final merged results block.

Review Comment:
   This allows all threads to perform the merge. In the old algorithm, the 
merge is done by a single thread.



-- 
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]

Reply via email to