yadavay-amzn commented on code in PR #56243:
URL: https://github.com/apache/spark/pull/56243#discussion_r3364200357


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/CoalesceShufflePartitions.scala:
##########
@@ -90,9 +90,38 @@ case class CoalesceShufflePartitions(session: SparkSession) 
extends AQEShuffleRe
       }
     }
 
+    // For groups that feed a partitioned join 
(SortMergeJoin/ShuffledHashJoin), enforce a
+    // minimum partition count to avoid eliminating join parallelism.
+    // Design choice: we use a pre-coalesce floor (Option A) rather than 
post-coalesce skew
+    // re-checking (Option B). Option A is simpler and avoids re-running skew 
detection after
+    // coalescing. Option B would be more robust for edge cases but adds 
significant complexity
+    // and can be explored as a follow-up.
+    val adjustedMinNumPartitionsByGroup = 
coalesceGroups.zip(minNumPartitionsByGroup).map {
+      case (group, minNum) if group.feedsJoin =>
+        val totalSize = group.shuffleStages.flatMap(

Review Comment:
   Added a comment explaining the invariant (mapStats is always Some after 
stage materialization). The flatMap safely degrades to 0 if stats are 
unexpectedly absent, which triggers the tiny-data path and skips the floor — 
preserving correctness.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to