You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by li...@apache.org on 2018/12/17 07:40:18 UTC
[spark] branch master updated: [SPARK-26327][SQL][FOLLOW-UP]
Refactor the code and restore the metrics name
This is an automated email from the ASF dual-hosted git repository.
lixiao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 5960a82 [SPARK-26327][SQL][FOLLOW-UP] Refactor the code and restore the metrics name
5960a82 is described below
commit 5960a8297ca06a4c62f39a8821dba4ba172f2bfc
Author: gatorsmile <ga...@gmail.com>
AuthorDate: Sun Dec 16 23:40:06 2018 -0800
[SPARK-26327][SQL][FOLLOW-UP] Refactor the code and restore the metrics name
## What changes were proposed in this pull request?
- The original comment about `updateDriverMetrics` is not right.
- Refactor the code to ensure `selectedPartitions ` has been set before sending the driver-side metrics.
- Restore the original name, which is more general and extendable.
## How was this patch tested?
The existing tests.
Closes #23328 from gatorsmile/followupSpark-26142.
Authored-by: gatorsmile <ga...@gmail.com>
Signed-off-by: gatorsmile <ga...@gmail.com>
---
.../spark/sql/execution/DataSourceScanExec.scala | 39 +++++++++++-----------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/DataSourceScanExec.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/DataSourceScanExec.scala
index c0fa4e7..322ffff 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/DataSourceScanExec.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/DataSourceScanExec.scala
@@ -17,7 +17,7 @@
package org.apache.spark.sql.execution
-import scala.collection.mutable.ArrayBuffer
+import scala.collection.mutable.{ArrayBuffer, HashMap}
import org.apache.commons.lang3.StringUtils
import org.apache.hadoop.fs.{BlockLocation, FileStatus, LocatedFileStatus, Path}
@@ -167,14 +167,26 @@ case class FileSourceScanExec(
partitionSchema = relation.partitionSchema,
relation.sparkSession.sessionState.conf)
- private var fileListingTime = 0L
+ val driverMetrics: HashMap[String, Long] = HashMap.empty
+
+ /**
+ * Send the driver-side metrics. Before calling this function, selectedPartitions has
+ * been initialized. See SPARK-26327 for more details.
+ */
+ private def sendDriverMetrics(): Unit = {
+ driverMetrics.foreach(e => metrics(e._1).add(e._2))
+ val executionId = sparkContext.getLocalProperty(SQLExecution.EXECUTION_ID_KEY)
+ SQLMetrics.postDriverMetricUpdates(sparkContext, executionId,
+ metrics.filter(e => driverMetrics.contains(e._1)).values.toSeq)
+ }
@transient private lazy val selectedPartitions: Seq[PartitionDirectory] = {
val optimizerMetadataTimeNs = relation.location.metadataOpsTimeNs.getOrElse(0L)
val startTime = System.nanoTime()
val ret = relation.location.listFiles(partitionFilters, dataFilters)
+ driverMetrics("numFiles") = ret.map(_.files.size.toLong).sum
val timeTakenMs = ((System.nanoTime() - startTime) + optimizerMetadataTimeNs) / 1000 / 1000
- fileListingTime = timeTakenMs
+ driverMetrics("metadataTime") = timeTakenMs
ret
}
@@ -286,8 +298,6 @@ case class FileSourceScanExec(
}
private lazy val inputRDD: RDD[InternalRow] = {
- // Update metrics for taking effect in both code generation node and normal node.
- updateDriverMetrics()
val readFile: (PartitionedFile) => Iterator[InternalRow] =
relation.fileFormat.buildReaderWithPartitionValues(
sparkSession = relation.sparkSession,
@@ -298,12 +308,14 @@ case class FileSourceScanExec(
options = relation.options,
hadoopConf = relation.sparkSession.sessionState.newHadoopConfWithOptions(relation.options))
- relation.bucketSpec match {
+ val readRDD = relation.bucketSpec match {
case Some(bucketing) if relation.sparkSession.sessionState.conf.bucketingEnabled =>
createBucketedReadRDD(bucketing, readFile, selectedPartitions, relation)
case _ =>
createNonBucketedReadRDD(readFile, selectedPartitions, relation)
}
+ sendDriverMetrics()
+ readRDD
}
override def inputRDDs(): Seq[RDD[InternalRow]] = {
@@ -313,7 +325,7 @@ case class FileSourceScanExec(
override lazy val metrics =
Map("numOutputRows" -> SQLMetrics.createMetric(sparkContext, "number of output rows"),
"numFiles" -> SQLMetrics.createMetric(sparkContext, "number of files"),
- "fileListingTime" -> SQLMetrics.createMetric(sparkContext, "file listing time (ms)"),
+ "metadataTime" -> SQLMetrics.createMetric(sparkContext, "metadata time"),
"scanTime" -> SQLMetrics.createTimingMetric(sparkContext, "scan time"))
protected override def doExecute(): RDD[InternalRow] = {
@@ -504,19 +516,6 @@ case class FileSourceScanExec(
}
}
- /**
- * Send the updated metrics to driver, while this function calling, selectedPartitions has
- * been initialized. See SPARK-26327 for more detail.
- */
- private def updateDriverMetrics() = {
- metrics("numFiles").add(selectedPartitions.map(_.files.size.toLong).sum)
- metrics("fileListingTime").add(fileListingTime)
-
- val executionId = sparkContext.getLocalProperty(SQLExecution.EXECUTION_ID_KEY)
- SQLMetrics.postDriverMetricUpdates(sparkContext, executionId,
- metrics("numFiles") :: metrics("fileListingTime") :: Nil)
- }
-
override def doCanonicalize(): FileSourceScanExec = {
FileSourceScanExec(
relation,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org