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


##########
pinot-query-planner/src/main/java/org/apache/calcite/rel/rules/PinotRuleUtils.java:
##########
@@ -68,19 +69,28 @@ public static boolean isAggregate(RelNode rel) {
   }
 
   // TODO: optimize this part out as it is not efficient to scan the entire 
subtree for exchanges.
-  public static boolean noExchangeInSubtree(RelNode relNode) {
-    if (relNode instanceof HepRelVertex) {
-      relNode = ((HepRelVertex) relNode).getCurrentRel();
-    }
-    if (relNode instanceof Exchange) {
+  public static boolean canPushDynamicBroadcastToLeaf(RelNode relNode) {
+    relNode = PinotRuleUtils.unboxRel(relNode);
+    if (relNode instanceof TableScan) {
+      // reaching table means it is plannable.
+      return true;
+    } else if (relNode instanceof Exchange) {
+      // we do not allow any exchanges in between join and table scan.
       return false;
-    }
-    for (RelNode child : relNode.getInputs()) {
-      if (!noExchangeInSubtree(child)) {
+    } else if (relNode instanceof Join) {
+      // always check only the left child for dynamic broadcast
+      return canPushDynamicBroadcastToLeaf(((Join) relNode).getLeft());

Review Comment:
   Do we have guarantee this is semi join instead of inner join?



##########
pinot-query-planner/src/main/java/org/apache/calcite/rel/rules/PinotRuleUtils.java:
##########
@@ -68,19 +69,28 @@ public static boolean isAggregate(RelNode rel) {
   }
 
   // TODO: optimize this part out as it is not efficient to scan the entire 
subtree for exchanges.
-  public static boolean noExchangeInSubtree(RelNode relNode) {
-    if (relNode instanceof HepRelVertex) {
-      relNode = ((HepRelVertex) relNode).getCurrentRel();
-    }
-    if (relNode instanceof Exchange) {
+  public static boolean canPushDynamicBroadcastToLeaf(RelNode relNode) {
+    relNode = PinotRuleUtils.unboxRel(relNode);
+    if (relNode instanceof TableScan) {
+      // reaching table means it is plannable.
+      return true;
+    } else if (relNode instanceof Exchange) {
+      // we do not allow any exchanges in between join and table scan.
       return false;
-    }
-    for (RelNode child : relNode.getInputs()) {
-      if (!noExchangeInSubtree(child)) {
+    } else if (relNode instanceof Join) {
+      // always check only the left child for dynamic broadcast
+      return canPushDynamicBroadcastToLeaf(((Join) relNode).getLeft());
+    } else if (relNode instanceof Aggregate) {
+      // if there's aggregation before join, join cannot be planned as dynamic 
broadcast.
+      return false;

Review Comment:
   How do we differentiate aggregate after join vs join after aggregate?



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/MultiStageOperator.java:
##########
@@ -37,11 +37,13 @@ public abstract class MultiStageOperator implements 
Operator<TransferableBlock>,
   protected final String _operatorId;
   protected final OpChainStats _opChainStats;
   protected boolean _isEarlyTerminated;
+  protected boolean _isFinished;

Review Comment:
   This shouldn't be added to the base



##########
pinot-query-planner/src/main/java/org/apache/calcite/rel/rules/PinotJoinToDynamicBroadcastRule.java:
##########
@@ -142,7 +142,7 @@ public boolean matches(RelOptRuleCall call) {
     RelNode right = join.getRight() instanceof HepRelVertex ? ((HepRelVertex) 
join.getRight()).getCurrentRel()
         : join.getRight();
     return left instanceof Exchange && right instanceof Exchange
-        && PinotRuleUtils.noExchangeInSubtree(left.getInput(0))
+        && PinotRuleUtils.canPushDynamicBroadcastToLeaf(left.getInput(0))

Review Comment:
   Not introduced in this PR, but can we break these checks into multiple 
steps? We should avoid doing the expensive `canPushDynamicBroadcastToLeaf()` 
unless all other checks pass



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/LeafStageTransferableBlockOperator.java:
##########
@@ -113,6 +113,9 @@ public String toExplainString() {
 
   @Override
   protected TransferableBlock getNextBlock() {
+    if (_isFinished) {

Review Comment:
   Why do we need this? We shouldn't need this unless the upstream operator 
breaks the contract of not calling next block when EOS is already returned



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/plan/server/ServerOpChainExecutionContext.java:
##########
@@ -0,0 +1,86 @@
+/**
+ * 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.query.runtime.plan.server;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import org.apache.pinot.common.request.PinotQuery;
+import org.apache.pinot.core.query.executor.QueryExecutor;
+import org.apache.pinot.core.query.request.ServerQueryRequest;
+import org.apache.pinot.query.planner.plannode.PlanNode;
+import org.apache.pinot.query.runtime.plan.DistributedStagePlan;
+import org.apache.pinot.query.runtime.plan.OpChainExecutionContext;
+
+
+/**
+ * Extension of the {@link OpChainExecutionContext} for {@link 
DistributedStagePlan} runs on leaf-stage.
+ *
+ * The difference is that: on a leaf-stage server node, {@link PlanNode} are 
split into {@link PinotQuery} part and
+ * {@link org.apache.pinot.query.runtime.operator.OpChain} part and are 
connected together in this context.
+ */
+public class ServerOpChainExecutionContext extends OpChainExecutionContext {

Review Comment:
   Suggest not introducing this as subclass but keep the existing 
`ServerPlanRequestContext`. If you find these extra properties apply to 
`OpChain` in general, we may directly add them into `OpChainExecutionContext`



-- 
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-unsubscr...@pinot.apache.org

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


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

Reply via email to