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


##########
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(
+          _.shuffleStage.mapStats.map(_.bytesByPartitionId.sum)).sum
+        val advisorySize = advisoryPartitionSize(group)
+        if (totalSize <= advisorySize) {
+          // Tiny data: all join data fits in one advisory-sized partition, so 
coalescing
+          // to 1 is fine -- no parallelism benefit from multiple partitions.
+          minNum
+        } else {
+          // When COALESCE_PARTITIONS_MIN_PARTITION_NUM is explicitly set, use 
it as the floor.
+          // Otherwise, compute a data-aware floor: the number of partitions 
needed to keep each
+          // partition at or below the advisory target size. The max(2, ...) 
ensures we never
+          // collapse to a single reducer for join data -- for totalSize 
between advisorySize and
+          // 2*advisorySize, ceil gives 1 or 2, so the floor of 2 prevents 
single-partition joins.
+          val joinFloor = 
conf.getConf(SQLConf.COALESCE_PARTITIONS_MIN_PARTITION_NUM)

Review Comment:
   Good point — restructured. When the config is explicitly set, we now 
early-return `minNum` (which already incorporates the config). The data-aware 
heuristic only applies in the else branch (config not set).



-- 
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