Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18159#discussion_r125389877
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/commands.scala 
---
    @@ -47,10 +56,73 @@ trait RunnableCommand extends logical.Command {
     }
     
     /**
    + * A special `RunnableCommand` which writes data out and updates metrics.
    + */
    +trait DataWritingCommand extends RunnableCommand {
    +
    +  override lazy val metrics: Map[String, SQLMetric] = {
    +    val sparkContext = SparkContext.getActive.get
    +    Map(
    +      "avgTime" -> SQLMetrics.createMetric(sparkContext, "average writing 
time (ms)"),
    +      "numFiles" -> SQLMetrics.createMetric(sparkContext, "number of 
written files"),
    +      "numOutputBytes" -> SQLMetrics.createMetric(sparkContext, "bytes of 
written output"),
    +      "numOutputRows" -> SQLMetrics.createMetric(sparkContext, "number of 
output rows"),
    +      "numParts" -> SQLMetrics.createMetric(sparkContext, "number of 
dynamic part")
    +    )
    +  }
    +
    +  /**
    +   * Callback function that update metrics collected from the writing 
operation.
    +   */
    +  protected def updateWritingMetrics(writeSummaries: 
Seq[ExecutedWriteSummary]): Unit = {
    +    val sparkContext = SparkContext.getActive.get
    +    var numPartitions = 0
    +    var numFiles = 0
    +    var totalNumBytes: Long = 0L
    +    var totalNumOutput: Long = 0L
    +    var totalWritingTime: Long = 0L
    +    var numFilesNonZeroWritingTime = 0
    +
    +    writeSummaries.foreach { summary =>
    +      numPartitions += summary.updatedPartitions.size
    +      numFiles += summary.numOutputFile
    +      totalNumBytes += summary.numOutputBytes
    +      totalNumOutput += summary.numOutputRows
    +      totalWritingTime += summary.totalWritingTime
    +      numFilesNonZeroWritingTime += summary.numFilesWithNonZeroWritingTime
    +    }
    +
    +    // We only count non-zero writing time when averaging total writing 
time.
    +    // The time for writing individual file can be zero if it's less than 
1 ms. Zero values can
    --- End diff --
    
    This only happens if a partition is very small, right?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to