You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "ulysses-you (via GitHub)" <gi...@apache.org> on 2023/05/24 04:09:35 UTC

[GitHub] [spark] ulysses-you commented on a diff in pull request #40312: [SPARK-42695][SQL] Skew join handling in stream side of broadcast hash join

ulysses-you commented on code in PR #40312:
URL: https://github.com/apache/spark/pull/40312#discussion_r1203392754


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/OptimizeSkewedJoin.scala:
##########
@@ -215,6 +216,32 @@ case class OptimizeSkewedJoin(ensureRequirements: EnsureRequirements)
         case (newLeft, newRight) =>
           shj.copy(left = newLeft, right = newRight, isSkewJoin = true)
       }.getOrElse(shj)
+
+    case bhj @ BroadcastHashJoinExec(_, _, joinType, _, _, ShuffleStage(s: ShuffleQueryStageExec),
+    BroadcastQueryStageExec(_, _, _), _, false) if canSplitLeftSide(joinType) =>
+      optimizeBroadcastHashJoin(s).map(newLeft => bhj.copy(left = newLeft, isSkewJoin = true))
+        .getOrElse(bhj)
+
+    case bhj @ BroadcastHashJoinExec(_, _, joinType, _, _, BroadcastQueryStageExec(_, _, _),
+    ShuffleStage(s: ShuffleQueryStageExec), _, false) if canSplitRightSide(joinType) =>
+      optimizeBroadcastHashJoin(s).map(newRight => bhj.copy(right = newRight, isSkewJoin = true))
+        .getOrElse(bhj)
+  }
+
+  private def optimizeBroadcastHashJoin(shuffleStage: ShuffleQueryStageExec): Option[SparkPlan] = {
+
+    def isSkewed(stats: MapOutputStatistics): Boolean = {
+      val medSize = Utils.median(stats.bytesByPartitionId, false)
+      val skewThreshold = getSkewThreshold(medSize)
+      stats.bytesByPartitionId.exists(_ > skewThreshold)
+    }
+
+    if (!shuffleStage.mapStats.forall(isSkewed(_))) {
+      return None
+    }
+
+    Some(SkewJoinChildWrapper(AQEShuffleReadExec(shuffleStage,
+      OptimizeShuffleWithLocalRead.getPartitionSpecs(shuffleStage, None))))

Review Comment:
   How can it handle skewed partition ? The code in `OptimizeShuffleWithLocalRead.getPartitionSpecs` does not take reduce partition size into account.



-- 
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: reviews-unsubscribe@spark.apache.org

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