cloud-fan commented on a change in pull request #28175: 
[SPARK-31253][SQL][FOLLOW-UP] Improve the partition data size metrics in 
CustomShuffleReaderExec
URL: https://github.com/apache/spark/pull/28175#discussion_r409247865
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/CustomShuffleReaderExec.scala
 ##########
 @@ -95,54 +97,67 @@ case class CustomShuffleReaderExec private(
     case _ => None
   }
 
-  private def partitionDataSizeMetrics = {
-    val maxSize = SQLMetrics.createSizeMetric(sparkContext, "maximum partition 
data size")
-    val minSize = SQLMetrics.createSizeMetric(sparkContext, "minimum partition 
data size")
-    val avgSize = SQLMetrics.createSizeMetric(sparkContext, "average partition 
data size")
-    val mapStatsOpt = shuffleStage.get.mapStats
-    val sizes = mapStatsOpt.map { mapStats =>
-      val mapSizes = mapStats.bytesByPartitionId
-      partitionSpecs.map {
-        case CoalescedPartitionSpec(startReducerIndex, endReducerIndex) =>
-          startReducerIndex.until(endReducerIndex).map(mapSizes).sum
-        case p: PartialReducerPartitionSpec => p.dataSize
-        case p => throw new IllegalStateException("unexpected " + p)
+  private def sendDriverMetrics(): Unit = {
+    val executionId = 
sparkContext.getLocalProperty(SQLExecution.EXECUTION_ID_KEY)
+    var driverAccumUpdates: Seq[(Long, Long)] = Seq.empty
+
+    val numPartitionsMetric = metrics("numPartitions")
+    numPartitionsMetric.set(partitionSpecs.length)
+    driverAccumUpdates = driverAccumUpdates :+
+      (numPartitionsMetric.id, partitionSpecs.length.toLong)
+
+    if (hasSkewedPartition) {
+      val skewedMetric = metrics("numSkewedPartitions")
+      val numSkewedPartitions = partitionSpecs.collect {
+        case p: PartialReducerPartitionSpec => p.reducerIndex
+      }.distinct.length
+      driverAccumUpdates = driverAccumUpdates :+ (skewedMetric.id, 
numSkewedPartitions.toLong)
+    }
+
+    if(!isLocalReader && shuffleStage.get.mapStats.isDefined) {
+      val partitionMetrics = metrics("partitionDataSize")
+      val mapStats = shuffleStage.get.mapStats
+
+      if (mapStats.isEmpty) {
 
 Review comment:
   This is unreacheable as the if condition has 
`shuffleStage.get.mapStats.isDefined`. But we do need to set size as 0 if 
`mapStats.isEmpty` as it means no partitions.

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


With regards,
Apache Git Services

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

Reply via email to