Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/9215#discussion_r42957236
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/util/DataFrameCallbackSuite.scala
---
@@ -80,4 +80,71 @@ class DataFrameCallbackSuite extends QueryTest with
SharedSQLContext {
assert(metrics(0)._2.analyzed.isInstanceOf[Project])
assert(metrics(0)._3.getMessage == e.getMessage)
}
+
+ test("get numRows metrics by callback") {
+ val metrics = ArrayBuffer.empty[Long]
+ val listener = new QueryExecutionListener {
+ // Only test successful case here, so no need to implement
`onFailure`
+ override def onFailure(funcName: String, qe: QueryExecution,
exception: Exception): Unit = {}
+
+ override def onSuccess(funcName: String, qe: QueryExecution,
duration: Long): Unit = {
+ metrics += qe.executedPlan.longMetric("numInputRows").value.value
+ }
+ }
+ sqlContext.listenerManager.register(listener)
+
+ val df = Seq(1 -> "a").toDF("i", "j").groupBy("i").count()
+ df.collect()
+ df.collect()
+ Seq(1 -> "a", 2 -> "a").toDF("i", "j").groupBy("i").count().collect()
+
+ assert(metrics.length == 3)
+ assert(metrics(0) == 1)
+ assert(metrics(1) == 1)
+ assert(metrics(2) == 2)
+ }
+
+ // TODO: Currently some LongSQLMetric use -1 as initial value, so if the
accumulator is never
+ // updated, we can filter it out later. However, when we aggregate(sum)
accumulator values at
+ // driver side for SQL physical operators, these -1 values will make our
result smaller.
+ // A easy fix is to create a new SQLMetric(including new MetricValue,
MetricParam, etc.), but we
+ // can do it later because the impact is just too small (1048576 tasks
for 1 MB).
+ ignore("get size metrics by callback") {
+ val metrics = ArrayBuffer.empty[Long]
+ val listener = new QueryExecutionListener {
+ // Only test successful case here, so no need to implement
`onFailure`
+ override def onFailure(funcName: String, qe: QueryExecution,
exception: Exception): Unit = {}
+
+ override def onSuccess(funcName: String, qe: QueryExecution,
duration: Long): Unit = {
+ metrics += qe.executedPlan.longMetric("dataSize").value.value
+ val bottomAgg = qe.executedPlan.children(0).children(0)
+ metrics += bottomAgg.longMetric("dataSize").value.value
+ }
+ }
+ sqlContext.listenerManager.register(listener)
+
+ val sparkListener = new SaveInfoListener
+ sqlContext.sparkContext.addSparkListener(sparkListener)
+
+ val df = (1 to 100).map(i => i -> i.toString).toDF("i", "j")
+ df.groupBy("i").count().collect()
+
+ def getPeakExecutionMemory(stageId: Int): Long = {
+ val peakMemoryAccumulator =
sparkListener.getCompletedStageInfos(stageId).accumulables
+ .filter(_._2.name == InternalAccumulator.PEAK_EXECUTION_MEMORY)
+
+ assert(peakMemoryAccumulator.size == 1)
+ peakMemoryAccumulator.head._2.value.toLong
+ }
+
+ assert(sparkListener.getCompletedStageInfos.length == 2)
+ val bottomAggDataSize = getPeakExecutionMemory(0)
+ val topAggDataSize = getPeakExecutionMemory(1)
+
+ // For this simple case, the peakExecutionMemory of a stage should be
the data size of the
+ // aggregate operator, as we only have one memory consuming operator
per stage.
+ assert(metrics.length == 2)
+ assert(metrics(0) == topAggDataSize)
+ assert(metrics(1) == bottomAggDataSize)
+ }
--- End diff --
good catch!
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]