Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/12352#discussion_r60180155
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileScanRDD.scala
---
@@ -53,33 +55,77 @@ class FileScanRDD(
override def compute(split: Partition, context: TaskContext):
Iterator[InternalRow] = {
val iterator = new Iterator[Object] with AutoCloseable {
+ private val inputMetrics = context.taskMetrics().inputMetrics
+ private val existingBytesRead = inputMetrics.bytesRead
+
+ // Find a function that will return the FileSystem bytes read by
this thread. Do this before
+ // apply readFunction, because it might read some bytes.
+ private val getBytesReadCallback: Option[() => Long] =
+ SparkHadoopUtil.get.getFSBytesReadOnThreadCallback()
+
+ // For Hadoop 2.5+, we get our input bytes from thread-local Hadoop
FileSystem statistics.
+ // If we do a coalesce, however, we are likely to compute multiple
partitions in the same
+ // task and in the same thread, in which case we need to avoid
override values written by
+ // previous partitions (SPARK-13071).
+ private def updateBytesRead(): Unit = {
+ getBytesReadCallback.foreach { getBytesRead =>
+ inputMetrics.setBytesRead(existingBytesRead + getBytesRead())
+ }
+ }
+
+ // If we can't get the bytes read from the FS stats, fall back to
the file size,
+ // which may be inaccurate.
+ private def updateBytesReadWithFileSize(): Unit = {
+ if (getBytesReadCallback.isEmpty && currentFile != null) {
+ inputMetrics.incBytesRead(currentFile.length)
+ }
+ }
+
private[this] val files =
split.asInstanceOf[FilePartition].files.toIterator
+ private[this] var currentFile: PartitionedFile = null
private[this] var currentIterator: Iterator[Object] = null
def hasNext = (currentIterator != null && currentIterator.hasNext)
|| nextIterator()
- def next() = currentIterator.next()
+ def next() = {
+ val nextElement = currentIterator.next()
+ // TODO: we should have a better separation of row based and batch
based scan, so that we
--- End diff --
i think in the future maybe we should just make everything batch based, and
then this problem goes away.
---
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]