You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/12/19 21:31:37 UTC

[GitHub] [pinot] agavra commented on a diff in pull request #10006: [refactor] combine operator API changes

agavra commented on code in PR #10006:
URL: https://github.com/apache/pinot/pull/10006#discussion_r1052650102


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/combine/function/CombineFunction.java:
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.core.operator.combine.function;
+
+import org.apache.pinot.core.operator.blocks.results.BaseResultsBlock;
+
+
+public interface CombineFunction<T extends BaseResultsBlock> {
+
+  /**
+   * Merges a results block into the main mergeable results block.
+   * <p>NOTE: {@code blockToMerge} should contain the result for a segment without any exception. The errored segment
+   * result is already handled.
+   *
+   * @param mergedBlock The block that accumulates previous results. It should be modified to add the information of the
+   *                    other block.
+   * @param blockToMerge The new block that needs to be merged into the mergedBlock.
+   */
+  void mergeResultsBlocks(T mergedBlock, T blockToMerge);
+
+  /**
+   * Can be overridden for early termination. The input results block might not be mergeable.
+   */
+  default boolean isQuerySatisfied(T resultsBlock) {

Review Comment:
   nit: consider naming this `shouldEarlyTerminate`?



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/combine/function/CombineFunction.java:
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.core.operator.combine.function;
+
+import org.apache.pinot.core.operator.blocks.results.BaseResultsBlock;
+
+
+public interface CombineFunction<T extends BaseResultsBlock> {
+
+  /**
+   * Merges a results block into the main mergeable results block.
+   * <p>NOTE: {@code blockToMerge} should contain the result for a segment without any exception. The errored segment
+   * result is already handled.
+   *
+   * @param mergedBlock The block that accumulates previous results. It should be modified to add the information of the
+   *                    other block.
+   * @param blockToMerge The new block that needs to be merged into the mergedBlock.
+   */
+  void mergeResultsBlocks(T mergedBlock, T blockToMerge);
+
+  /**
+   * Can be overridden for early termination. The input results block might not be mergeable.
+   */
+  default boolean isQuerySatisfied(T resultsBlock) {
+    return false;
+  }
+
+  /**
+   * Converts the given results block into a mergeable results block if necessary.
+   */
+  default T convertToMergeableBlock(T resultsBlock) {

Review Comment:
   unclear if this is called once per `mergeResultsBlocks` or once at the very end. it would be nice to clarify that in the comment



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/combine/BaseSingleBlockCombineOperator.java:
##########
@@ -0,0 +1,139 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.combine;
+
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+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.ExceptionResultsBlock;
+import org.apache.pinot.core.operator.combine.function.CombineFunction;
+import org.apache.pinot.core.query.request.context.QueryContext;
+
+
+/**
+ * Base implementation of the combine operator.
+ * <p>Combine operator uses multiple worker threads to process segments in parallel, and uses the main thread to merge
+ * the results blocks from the processed segments. It can early-terminate the query to save the system resources if it
+ * detects that the merged results can already satisfy the query, or the query is already errored out or timed out.
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+public abstract class BaseSingleBlockCombineOperator<T extends BaseResultsBlock>

Review Comment:
   is this is called `SingleBlock` because it produces only a single block at the end? (as opposed to streaming, which might produce multiple?)



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/combine/function/CombineFunction.java:
##########
@@ -0,0 +1,32 @@
+package org.apache.pinot.core.operator.combine.function;
+
+import org.apache.pinot.core.operator.blocks.results.BaseResultsBlock;
+
+
+public interface CombineFunction<T extends BaseResultsBlock> {
+
+  /**
+   * Merges a results block into the main mergeable results block.
+   * <p>NOTE: {@code blockToMerge} should contain the result for a segment without any exception. The errored segment

Review Comment:
   this note is a little confusing, are you suggesting that `blockToMerge` should not have an exception so that the implementor of this method does not need to worry about checking whether or not the block has an exception in the metadata?



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/combine/BaseCombineOperator.java:
##########
@@ -54,7 +52,8 @@
  * detects that the merged results can already satisfy the query, or the query is already errored out or timed out.
  */
 @SuppressWarnings({"rawtypes", "unchecked"})
-public abstract class BaseCombineOperator<T extends BaseResultsBlock> extends BaseOperator<BaseResultsBlock> {

Review Comment:
   is the `_blockingQueue` held in this class still used anywhere?



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org