ankitsultana commented on code in PR #9838: URL: https://github.com/apache/pinot/pull/9838#discussion_r1028489610
########## pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/SmartShuffleRewriteVisitor.java: ########## @@ -0,0 +1,447 @@ +/** + * 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.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.commons.collections.CollectionUtils; +import org.apache.pinot.common.config.provider.TableCache; +import org.apache.pinot.core.transport.ServerInstance; +import org.apache.pinot.query.planner.StageMetadata; +import org.apache.pinot.query.planner.logical.PhysicalStageTraversalVisitor; +import org.apache.pinot.query.planner.logical.PhysicalStageTraversalVisitor.PhysicalStageInfo; +import org.apache.pinot.query.planner.logical.RexExpression; +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; + + +/** + * Some trivial implementation assumptions (very easy to remove): + * 1. If a stage A depends on stage B, stageId(A) < stageId(B) + * 2. Leaf stage can either be a MailboxReceiveNode or TableScanNode. + */ +public class SmartShuffleRewriteVisitor + implements StageNodeVisitor<DisjointSet<SmartShuffleRewriteVisitor.PartitionKey>, PhysicalStageInfo> { + 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, + * then the join-stage will have two partitioning keys: leftTable.userUUID and rightTable.userUUID. If the parent + * of the join stage is another join with the userUUID column of the leftTable, then we should be able to skip + * shuffle again. However to do that we need to detect that two keys are equivalent, and for that we use a + * DisjointSet. + */ Review Comment: todo: bug: servers need to be reassigned for non-join stage transfers when singleton is selected -- 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