You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "ankitsultana (via GitHub)" <gi...@apache.org> on 2023/04/04 06:35:49 UTC

[GitHub] [pinot] ankitsultana commented on a diff in pull request #10481: [refactor] add physical planner

ankitsultana commented on code in PR #10481:
URL: https://github.com/apache/pinot/pull/10481#discussion_r1156783663


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/DispatchablePlanContext.java:
##########
@@ -0,0 +1,64 @@
+/**
+ * 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.planner.physical;
+
+import java.util.HashMap;
+import java.util.List;
+import org.apache.calcite.util.Pair;
+import org.apache.pinot.query.context.PlannerContext;
+import org.apache.pinot.query.planner.QueryPlan;
+import org.apache.pinot.query.routing.WorkerManager;
+
+
+public class DispatchablePlanContext {
+  private final WorkerManager _workerManager;
+  private final long _requestId;
+  private final PlannerContext _plannerContext;
+  private final List<Pair<Integer, String>> _fields;
+  private final QueryPlan _queryPlan;
+
+  public DispatchablePlanContext(WorkerManager workerManager, long requestId, PlannerContext plannerContext,
+      List<Pair<Integer, String>> resultFields) {
+    _workerManager = workerManager;
+    _requestId = requestId;
+    _plannerContext = plannerContext;
+    _fields = resultFields;
+    _queryPlan = new QueryPlan(_fields, new HashMap<>(), new HashMap<>());
+  }
+
+  public QueryPlan getQueryPlan() {
+    return _queryPlan;
+  }
+
+  public WorkerManager getWorkerManager() {
+    return _workerManager;
+  }
+
+  public long getRequestId() {
+    return _requestId;
+  }
+
+  public PlannerContext getPlannerContext() {
+    return _plannerContext;
+  }
+
+  public List<Pair<Integer, String>> getFields() {

Review Comment:
   Where are the fields used?



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/DispatchablePlanVisitor.java:
##########
@@ -0,0 +1,147 @@
+/**
+ * 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.planner.physical;
+
+import org.apache.pinot.query.planner.StageMetadata;
+import org.apache.pinot.query.planner.stage.AggregateNode;
+import org.apache.pinot.query.planner.stage.FilterNode;
+import org.apache.pinot.query.planner.stage.JoinNode;
+import org.apache.pinot.query.planner.stage.MailboxReceiveNode;
+import org.apache.pinot.query.planner.stage.MailboxSendNode;
+import org.apache.pinot.query.planner.stage.ProjectNode;
+import org.apache.pinot.query.planner.stage.SortNode;
+import org.apache.pinot.query.planner.stage.StageNode;
+import org.apache.pinot.query.planner.stage.StageNodeVisitor;
+import org.apache.pinot.query.planner.stage.TableScanNode;
+import org.apache.pinot.query.planner.stage.ValueNode;
+import org.apache.pinot.query.planner.stage.WindowNode;
+
+
+public class DispatchablePlanVisitor implements StageNodeVisitor<Void, DispatchablePlanContext> {
+  public static final DispatchablePlanVisitor INSTANCE = new DispatchablePlanVisitor();
+
+  private DispatchablePlanVisitor() {
+  }
+
+  /**
+   * Entry point
+   * @param globalReceiverNode
+   * @param physicalPlanContext
+   */
+  public void constructDispatchablePlan(StageNode globalReceiverNode, DispatchablePlanContext physicalPlanContext) {
+    globalReceiverNode.visit(DispatchablePlanVisitor.INSTANCE, physicalPlanContext);
+    computeWorkerAssignment(globalReceiverNode, physicalPlanContext);
+  }
+
+  private StageMetadata getStageMetadata(StageNode node, DispatchablePlanContext context) {
+    return context.getQueryPlan().getStageMetadataMap().computeIfAbsent(
+        node.getStageId(), (id) -> new StageMetadata());
+  }
+
+  private void computeWorkerAssignment(StageNode node, DispatchablePlanContext context) {
+    int stageId = node.getStageId();
+    context.getWorkerManager().assignWorkerToStage(stageId, context.getQueryPlan().getStageMetadataMap().get(stageId),
+        context.getRequestId(), context.getPlannerContext().getOptions());
+  }
+
+  @Override
+  public Void visitAggregate(AggregateNode node, DispatchablePlanContext context) {
+    node.getInputs().get(0).visit(this, context);
+    StageMetadata stageMetadata = getStageMetadata(node, context);
+    stageMetadata.setRequireSingleton(node.getGroupSet().size() == 0 && AggregateNode.isFinalStage(node));

Review Comment:
   Just a note: after my change this information will be present in trait of the RelNode, which can then be passed into the AggregateNode during `walkRelPlan`.



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/DispatchablePlanVisitor.java:
##########
@@ -0,0 +1,147 @@
+/**
+ * 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.planner.physical;
+
+import org.apache.pinot.query.planner.StageMetadata;
+import org.apache.pinot.query.planner.stage.AggregateNode;
+import org.apache.pinot.query.planner.stage.FilterNode;
+import org.apache.pinot.query.planner.stage.JoinNode;
+import org.apache.pinot.query.planner.stage.MailboxReceiveNode;
+import org.apache.pinot.query.planner.stage.MailboxSendNode;
+import org.apache.pinot.query.planner.stage.ProjectNode;
+import org.apache.pinot.query.planner.stage.SortNode;
+import org.apache.pinot.query.planner.stage.StageNode;
+import org.apache.pinot.query.planner.stage.StageNodeVisitor;
+import org.apache.pinot.query.planner.stage.TableScanNode;
+import org.apache.pinot.query.planner.stage.ValueNode;
+import org.apache.pinot.query.planner.stage.WindowNode;
+
+
+public class DispatchablePlanVisitor implements StageNodeVisitor<Void, DispatchablePlanContext> {
+  public static final DispatchablePlanVisitor INSTANCE = new DispatchablePlanVisitor();
+
+  private DispatchablePlanVisitor() {
+  }
+
+  /**
+   * Entry point
+   * @param globalReceiverNode
+   * @param physicalPlanContext
+   */
+  public void constructDispatchablePlan(StageNode globalReceiverNode, DispatchablePlanContext physicalPlanContext) {
+    globalReceiverNode.visit(DispatchablePlanVisitor.INSTANCE, physicalPlanContext);
+    computeWorkerAssignment(globalReceiverNode, physicalPlanContext);

Review Comment:
   nit: we can remove `constructDispatchablePlan` by moving this `computeWorkerAssignment` call to `visitMailboxReceive`. The caller can then directly do `rootNode.visit(DispatchablePlanVisitor.INSTANCE, context)`:
   
   ```
   // special case for the global mailbox receive node
       if (node.getStageId() == 0) {
         context.getQueryPlan().getQueryStageMap().put(0, node);
         computeWorkerAssignment(globalReceiverNode, physicalPlanContext);
       }
   ```



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