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


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/AttachStageMetadata.java:
##########
@@ -0,0 +1,132 @@
+/**
+ * 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.logical;
+
+import java.util.HashMap;
+import java.util.List;
+import org.apache.calcite.util.Pair;
+import org.apache.pinot.query.planner.QueryPlan;
+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;
+
+
+/**
+ * {@code AttachStageMetadata} computes the {@link StageMetadata} for a {@link 
StageNode}
+ * tree and attaches it in the form of a {@link QueryPlan}.
+ */
+public class AttachStageMetadata implements StageNodeVisitor<Void, QueryPlan> {

Review Comment:
   nit: `StageMetadataVisitor`



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/QueryPlan.java:
##########
@@ -76,52 +73,6 @@ public List<Pair<Integer, String>> getQueryResultFields() {
   }
 
   public String explain() {

Review Comment:
   can we add a short javadoc for its purpose, esp. mentioning that this is 
different from the SQL of 
   ```
   EXPLAIN PLAN FOR (SELECT ...)
   ```
   



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/StagePlanner.java:
##########
@@ -49,11 +41,8 @@
  * This class is non-threadsafe. Do not reuse the stage planner for multiple 
query plans.
  */
 public class StagePlanner {
-  private final PlannerContext _plannerContext;
+  private PlannerContext _plannerContext;

Review Comment:
   ```suggestion
     private final PlannerContext _plannerContext;
   ```



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/StagePlanner.java:
##########
@@ -69,176 +58,68 @@ public StagePlanner(PlannerContext plannerContext, 
WorkerManager workerManager)
    */
   public QueryPlan makePlan(RelRoot relRoot) {
     RelNode relRootNode = relRoot.rel;
-    // clear the state
-    _queryStageMap = new HashMap<>();
-    _stageMetadataMap = new HashMap<>();
     // Stage ID starts with 1, 0 will be reserved for ROOT stage.
     _stageIdCounter = 1;
 
     // walk the plan and create stages.
     StageNode globalStageRoot = walkRelPlan(relRootNode, getNewStageId());
+    ShuffleRewriter.removeShuffles(globalStageRoot);

Review Comment:
   i would call this function `optimizeShuffles` instead of `removeShuffles`



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/executor/PhysicalPlanBuilder.java:
##########
@@ -0,0 +1,137 @@
+/**
+ * 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.executor;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.proto.Mailbox;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.transport.ServerInstance;
+import org.apache.pinot.query.mailbox.MailboxService;
+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.runtime.blocks.TransferableBlock;
+import org.apache.pinot.query.runtime.operator.AggregateOperator;
+import org.apache.pinot.query.runtime.operator.FilterOperator;
+import org.apache.pinot.query.runtime.operator.HashJoinOperator;
+import org.apache.pinot.query.runtime.operator.LiteralValueOperator;
+import org.apache.pinot.query.runtime.operator.MailboxReceiveOperator;
+import org.apache.pinot.query.runtime.operator.MailboxSendOperator;
+import org.apache.pinot.query.runtime.operator.SortOperator;
+import org.apache.pinot.query.runtime.operator.TransformOperator;
+
+
+public class PhysicalPlanBuilder implements 
StageNodeVisitor<Operator<TransferableBlock>, Void> {

Review Comment:
   nit `PhysicalPlanVisitor`



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/stage/MailboxReceiveNode.java:
##########
@@ -33,22 +33,30 @@ public class MailboxReceiveNode extends AbstractStageNode {
   @ProtoProperties
   private KeySelector<Object[], Object[]> _partitionKeySelector;
 
+  private StageNode _sender;

Review Comment:
   i dunno how to express what I meant but what I am looking for is something 
similar to:
   ```suggestion
     private transient StageNode _sender;
   ```
   
   e.g. express that this is only used for planning purpose and should not be 
part of the property of this node at stage plan



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/executor/WorkerQueryExecutor.java:
##########
@@ -62,16 +41,11 @@
  */
 public class WorkerQueryExecutor {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(WorkerQueryExecutor.class);
-  private PinotConfiguration _config;
-  private ServerMetrics _serverMetrics;
   private MailboxService<Mailbox.MailboxContent> _mailboxService;
   private String _hostName;
   private int _port;
 
-  public void init(PinotConfiguration config, ServerMetrics serverMetrics,
-      MailboxService<Mailbox.MailboxContent> mailboxService, String hostName, 
int port) {
-    _config = config;
-    _serverMetrics = serverMetrics;
+  public void init(MailboxService<Mailbox.MailboxContent> mailboxService, 
String hostName, int port) {

Review Comment:
   do not remove config and servermetrics for now



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/MailboxReceiveOperator.java:
##########
@@ -79,6 +79,12 @@ public 
MailboxReceiveOperator(MailboxService<Mailbox.MailboxContent> mailboxServ
           singletonInstance = serverInstance;
         }
       }
+
+      // FIXME: there's a bug where singletonInstance may be null in the case 
of a JOIN where
+      // one side is BROADCAST and the other is SINGLETON (this is the case 
with nested loop
+      // joins for inequality conditions). This causes NPEs in the logs, but 
actually works
+      // because the side that hits the NPE doesn't expect to get any data 
anyway (that's the
+      // side that gets the broadcast from one side but nothing from the 
SINGLETON)

Review Comment:
   can we create an issue and link it here?



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/QueryRunner.java:
##########
@@ -87,7 +87,7 @@ public void init(PinotConfiguration config, 
InstanceDataManager instanceDataMana
       _serverExecutor = new ServerQueryExecutorV1Impl();
       _serverExecutor.init(config, instanceDataManager, serverMetrics);
       _workerExecutor = new WorkerQueryExecutor();
-      _workerExecutor.init(config, serverMetrics, _mailboxService, _hostname, 
_port);
+      _workerExecutor.init(_mailboxService, _hostname, _port);

Review Comment:
   this isn't fixed



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/ShuffleRewriter.java:
##########
@@ -0,0 +1,171 @@
+/**
+ * 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.logical;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.calcite.rel.RelDistribution;
+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;
+
+
+public class ShuffleRewriter implements StageNodeVisitor<Set<Integer>, Void> {

Review Comment:
   nit `ShuffleRewriteVisitor`



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