You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "wangyum (via GitHub)" <gi...@apache.org> on 2023/05/25 07:52:16 UTC
[GitHub] [spark] wangyum commented on a diff in pull request #40312: [SPARK-42695][SQL] Skew join handling in stream side of broadcast hash join
wangyum commented on code in PR #40312:
URL: https://github.com/apache/spark/pull/40312#discussion_r1205132132
##########
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:
There will be no skew if do not put the same join key values together. This optimization assumes that the data in the map stage does not have skew values (usually it is true). I don’t know if databricks has any other ideas? @cloud-fan
--
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