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/11/30 08:20:05 UTC

[GitHub] [pinot] ankitsultana commented on a diff in pull request #9873: [multistage] Add Pluggable Physical Optimizers + Greedy Shuffle Skip Optimizer

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


##########
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;
+
+  /**
+   * A shuffle optimizer that can avoid shuffles by taking into account all of the following:
+   * 1. Servers assigned to the stages. The optimizer may also choose to change the server assignment if skipping
+   *    shuffles is possible.
+   * 2. The hash-algorithm and physical number of partitions of the data in sender/receiver nodes
+   *    So for instance if we do a join on two tables where the left table is partitioned using Murmur but the
+   *    right table is partitioned using hashCode, then this optimizer can detect this case and keep the shuffle.
+   * 3. Equivalent partitioning introduced by doing a join. e.g. if we do a join on two tables on a user_uuid column,

Review Comment:
   This third point is no longer valid. Will remove in next revision.



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