walterddr commented on code in PR #9873:
URL: https://github.com/apache/pinot/pull/9873#discussion_r1047408268


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/QueryEnvironment.java:
##########
@@ -221,7 +225,7 @@ private RelNode optimize(RelRoot relRoot, PlannerContext 
plannerContext) {
 
   private QueryPlan toDispatchablePlan(RelRoot relRoot, PlannerContext 
plannerContext, long requestId) {
     // 5. construct a dispatchable query plan.
-    StagePlanner queryStagePlanner = new StagePlanner(plannerContext, 
_workerManager, requestId);
+    StagePlanner queryStagePlanner = new StagePlanner(plannerContext, 
_workerManager, requestId, _tableCache);
     return queryStagePlanner.makePlan(relRoot);

Review Comment:
   my understanding of this POC is that. the end goal is to, within 
StagePlanner, assign each stage a parallelism and a set of servers to run those 
parallelism. is this correct?



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/SmartShuffleRewriteVisitor.java:
##########
@@ -0,0 +1,468 @@
+/**
+ * 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 com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.calcite.rel.RelDistribution;
+import org.apache.pinot.common.config.provider.TableCache;
+import org.apache.pinot.core.transport.ServerInstance;
+import org.apache.pinot.query.planner.QueryPlan;
+import org.apache.pinot.query.planner.StageMetadata;
+import org.apache.pinot.query.planner.logical.RexExpression;
+import org.apache.pinot.query.planner.logical.StageLayoutVisitor;
+import org.apache.pinot.query.planner.logical.StageLayoutVisitor.StageLayout;
+import org.apache.pinot.query.planner.partitioning.FieldSelectionKeySelector;
+import org.apache.pinot.query.planner.partitioning.KeySelector;
+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.spi.config.table.ColumnPartitionConfig;
+import org.apache.pinot.spi.config.table.IndexingConfig;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This shuffle optimizer uses a {@link Set<PartitionKey>} to keep track of 
partition-keys for each inner stage node.
+ * If there are two partition keys P1 and P2 in the set for a given inner 
stage node, that means the data for that
+ * stage is partitioned by both P1 and P2 (independently). An example instance 
where this can happen is a join stage.
+ * In the join-stage, the data in that stage is partitioned by both a 
partition-key on the left and a partition-key
+ * on the right.
+ *
+ * If a sending stage has the keys {P1, P2} and the receiving stage needs data 
partitioned by P1, then a shuffle is
+ * not needed. Moreover, if P1 = [0, 1] and the keys are again {P1, P2} (value 
of P2 is arbitrary), if the receiving
+ * stage needs data partitioned by [0, 1, 2], then again no shuffle is needed.
+ *
+ * Also see: {@link PartitionKey} for its definition.
+ * TODO: Use a smarter and more appropriate name than 
"SmartShuffleRewriterVisitor".
+ */
+public class SmartShuffleRewriteVisitor
+    implements StageNodeVisitor<Set<SmartShuffleRewriteVisitor.PartitionKey>, 
StageLayout> {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(SmartShuffleRewriteVisitor.class);
+
+  private final TableCache _tableCache;
+  private final Map<Integer, StageMetadata> _stageMetadataMap;
+  private boolean _canSkipShuffleForJoin;

Review Comment:
   IIUC, the idea here is that,
   1. there are some additional metadata that needs to be computed to run the 
colocated-join smart shuffle visitor. (e.g. the StageLayout context)
   2. then the smartShuffleVisitor is run and produces something locally 
private to the visitor itself. 
   
   with these 2 assumptions. we can probably make WorkerAssignmentVisitor as an 
SPI and load them dynamically based on query option. 
   
   I am thinking of something like this:
   
   
   QueryEnvironment adds 
   ```
   _workerAssignmentStrategyFactory;
   runWorkerAssignmentStrategy(QueryPlan, WorkerManager);
   ```
   
   added class `WorkerAssignmentStrategyFactory` with
   ```
   WorkerAssignmentStrategy strategy = 
WorkerAssignmentStrategyFactory.createStrategy(QueryPlan, WorkerManager);
   ```
    to create different worker assignment strategy based on QueryPlan
   
   another class `WorkerAssignmentStrategy` that
   ```
   WorkerAssignmentStrategy<Context, Layout> implements 
StageNodeVisitor<Context, Layout>
   ```
   



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/StagePlanner.java:
##########
@@ -84,6 +89,9 @@ public QueryPlan makePlan(RelRoot relRoot) {
       _workerManager.assignWorkerToStage(e.getKey(), e.getValue(), _requestId);
     }
 
+    // Run physical optimizations
+    runPhysicalOptimizers(queryPlan);
+

Review Comment:
   can we change this to `runWorkerAssignmentStrategy(queryPlan, 
_workerManager) and get rid of the 4 lines above ?



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