Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15307#discussion_r81873307
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/StreamExecution.scala
 ---
    @@ -511,12 +572,71 @@ class StreamExecution(
          """.stripMargin
       }
     
    +  /**
    +   * Report row metrics of the executed trigger
    +   * @param triggerExecutionPlan Execution plan of the trigger
    +   * @param triggerLogicalPlan Logical plan of the trigger, generated from 
the query logical plan
    +   * @param sourceToDataframe Source to DataFrame returned by the 
source.getBatch in this trigger
    +   */
    +  private def reportMetrics(
    +      triggerExecutionPlan: SparkPlan,
    +      triggerLogicalPlan: LogicalPlan,
    +      sourceToDataframe: Map[Source, DataFrame]): Unit = {
    +    val sourceToNumInputRows = StreamExecution.getNumInputRowsFromTrigger(
    +      triggerExecutionPlan, triggerLogicalPlan, sourceToDataframe)
    +    val numOutputRows = 
triggerExecutionPlan.metrics.get("numOutputRows").map(_.value)
    +    val stateNodes = triggerExecutionPlan.collect {
    +      case p if p.isInstanceOf[StateStoreSaveExec] => p
    +    }
    +    statusLock.synchronized 
{streamMetrics.reportNumRows(sourceToNumInputRows, numOutputRows)
    +      stateNodes.zipWithIndex.foreach { case (s, i) =>
    +        streamMetrics.reportTriggerStatus(
    +          NUM_TOTAL_STATE_ROWS(i + 1),
    +          s.metrics.get("numTotalStateRows").map(_.value).getOrElse(0L))
    +        streamMetrics.reportTriggerStatus(
    +          NUM_UPDATED_STATE_ROWS(i + 1),
    +          s.metrics.get("numUpdatedStateRows").map(_.value).getOrElse(0L))
    +      }
    +    }
    +  }
    +
    +  private def reportTimeTaken[T](triggerStatusKey: String)(body: => T): T 
= {
    +    val startTime = triggerClock.getTimeMillis()
    +    val result = body
    +    val endTime = triggerClock.getTimeMillis()
    +    statusLock.synchronized {
    +      streamMetrics.reportTriggerStatus(triggerStatusKey, math.max(endTime 
- startTime, 0))
    +    }
    +    result
    +  }
    +
    +  private def reportTimeTaken[T](source: Source, triggerStatusKey: 
String)(body: => T): T = {
    +    val startTime = triggerClock.getTimeMillis()
    +    val result = body
    +    val endTime = triggerClock.getTimeMillis()
    +    statusLock.synchronized {
    +      streamMetrics.reportSourceTriggerStatus(
    +        source, triggerStatusKey, math.max(endTime - startTime, 0))
    +    }
    +    result
    +  }
    +
    +  private def reportTimestamp(string: String): Unit = 
statusLock.synchronized {
    +    streamMetrics.reportTriggerStatus(string, triggerClock.getTimeMillis)
    +  }
    +
       private def toInfo: StreamingQueryInfo = {
    -    new StreamingQueryInfo(
    +    StreamingQueryInfo(
           this.name,
           this.id,
    +      triggerClock.getTimeMillis(),
    +      streamMetrics.currentInputRate,
    +      streamMetrics.currentProcessingRate,
    +      streamMetrics.currentOutputRate,
    +      streamMetrics.currentLatency,
    --- End diff --
    
    I would use named arguments when there are this any of the same type in a 
row.


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