You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/09/14 03:32:29 UTC

[GitHub] [spark] manuzhang commented on a change in pull request #29692: [SPARK-32830][SQL] Optimize Skewed BroadcastNestedLoopJoin with AQE

manuzhang commented on a change in pull request #29692:
URL: https://github.com/apache/spark/pull/29692#discussion_r487633146



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeSkewedJoin.scala
##########
@@ -248,6 +275,71 @@ case class OptimizeSkewedJoin(conf: SQLConf) extends Rule[SparkPlan] {
       } else {
         smj
       }
+
+    case bnl @ BroadcastNestedLoopJoinExec(
+    ShuffleStage(left: ShuffleStageInfo), _, BuildRight, joinType, _, _) =>
+      resolveBroadcastNLJoinSkew(bnl, left, joinType, BuildRight)
+    case bnl @ BroadcastNestedLoopJoinExec(
+    _, ShuffleStage(right: ShuffleStageInfo), BuildLeft, joinType, _, _) =>
+      resolveBroadcastNLJoinSkew(bnl, right, joinType, BuildLeft)
+  }
+
+  def resolveBroadcastNLJoinSkew(
+      bnl: BroadcastNestedLoopJoinExec,
+      stream: ShuffleStageInfo,
+      joinType: JoinType,
+      buildSide: BuildSide): SparkPlan = {
+    val streamMedSize = medianSize(stream.mapStats)
+    val numPartitions = stream.partitionsWithSizes.length
+    logDebug(
+      s"""
+         |Optimizing skewed join.
+         |${if (buildSide == BuildLeft) "Left" else "Right"} stream side partitions size info:
+         |${getSizeInfo(streamMedSize, stream.mapStats.bytesByPartitionId)}
+        """.stripMargin)
+    val streamActualSizes = stream.partitionsWithSizes.map(_._2)
+    val streamTargetSize = targetSize(streamActualSizes, streamMedSize)
+    val streamSidePartitions = mutable.ArrayBuffer.empty[ShufflePartitionSpec]
+    var numSkewedStream = 0
+    for (partitionIndex <- 0 until numPartitions) {

Review comment:
       This part looks like that in `optimizeSkewJoin`. Can we make it into a general method ?




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org