cloud-fan commented on a change in pull request #32883: URL: https://github.com/apache/spark/pull/32883#discussion_r652419451
########## File path: sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/ExpandShufflePartitions.scala ########## @@ -0,0 +1,98 @@ +/* + * 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.spark.sql.execution.adaptive + +import org.apache.spark.sql.catalyst.plans.physical.SinglePartition +import org.apache.spark.sql.execution.SparkPlan +import org.apache.spark.sql.execution.exchange.{EnsureRequirements, REPARTITION_BY_COL, REPARTITION_BY_NONE, ShuffleExchangeLike, ShuffleOrigin} +import org.apache.spark.sql.internal.SQLConf + +/** + * A rule to expand the shuffle partitions based on the map output statistics, which can + * avoid data skew that hurt performance. + * + * We use ADVISORY_PARTITION_SIZE_IN_BYTES size to decide if a partition should be expanded. + * Let's say we have 3 maps with 3 shuffle partitions, and assuming r1 has data skew issue. + * the map side looks like: + * m0:[b0, b1, b2], m1:[b0, b1, b2], m2:[b0, b1, b2] + * and the reduce side looks like: + * (without this rule) r1[m0-b1, m1-b1, m2-b1] + * / \ + * r0:[m0-b0, m1-b0, m2-b0], r1:[m0-b1], r2:[m1-b1], r3:[m2-b1], r4[m0-b2, m1-b2, m2-b2] + */ +object ExpandShufflePartitions extends CustomShuffleReaderRule { + override def supportedShuffleOrigins: Seq[ShuffleOrigin] = + Seq(REPARTITION_BY_COL, REPARTITION_BY_NONE) Review comment: This makes me think that if we need a new operator to do the repartition for partitioned table insertion (non partitioned table can use the existing operator, thanks to https://github.com/apache/spark/commit/ce1636948b1fb8cfb8cc921896dc003949da1085), and assign it a new shuffle origin. -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org