You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/04/27 09:53:17 UTC

[GitHub] [spark] viirya commented on a change in pull request #24473: [SPARK-27534][SQL] Do not load `content` column in binary data source if it is not selected

viirya commented on a change in pull request #24473: [SPARK-27534][SQL] Do not load `content` column in binary data source if it is not selected
URL: https://github.com/apache/spark/pull/24473#discussion_r279150117
 
 

 ##########
 File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/binaryfile/BinaryFileFormat.scala
 ##########
 @@ -101,43 +98,27 @@ class BinaryFileFormat extends FileFormat with DataSourceRegister {
     val filterFuncs = filters.map(filter => createFilterFunction(filter))
 
     file: PartitionedFile => {
-      val path = file.filePath
-      val fsPath = new Path(path)
-
+      val path = new Path(file.filePath)
       // TODO: Improve performance here: each file will recompile the glob pattern here.
-      if (pathGlobPattern.forall(new GlobFilter(_).accept(fsPath))) {
-        val fs = fsPath.getFileSystem(broadcastedHadoopConf.value.value)
-        val fileStatus = fs.getFileStatus(fsPath)
-        val length = fileStatus.getLen
-        val modificationTime = fileStatus.getModificationTime
-
-        if (filterFuncs.forall(_.apply(fileStatus))) {
-          val stream = fs.open(fsPath)
-          val content = try {
-            ByteStreams.toByteArray(stream)
-          } finally {
-            Closeables.close(stream, true)
-          }
-
-          val fullOutput = dataSchema.map { f =>
-            AttributeReference(f.name, f.dataType, f.nullable, f.metadata)()
-          }
-          val requiredOutput = fullOutput.filter { a =>
-            requiredSchema.fieldNames.contains(a.name)
+      if (pathGlobPattern.forall(new GlobFilter(_).accept(path))) {
+        val fs = path.getFileSystem(broadcastedHadoopConf.value.value)
+        val status = fs.getFileStatus(path)
+        if (filterFuncs.forall(_.apply(status))) {
+          val values = requiredSchema.fieldNames.map {
+            case PATH => UTF8String.fromString(status.getPath.toString)
+            case LENGTH => status.getLen
+            case MODIFICATION_TIME => DateTimeUtils.fromMillis(status.getModificationTime)
+            case CONTENT =>
+              val stream = fs.open(status.getPath)
+              try {
+                ByteStreams.toByteArray(stream)
+              } finally {
+                Closeables.close(stream, true)
+              }
+            case other =>
+              throw new RuntimeException(s"Unsupported field name: ${other}")
           }
-
-          // TODO: Add column pruning
-          // currently it still read the file content even if content column is not required.
-          val requiredColumns = GenerateUnsafeProjection.generate(requiredOutput, fullOutput)
-
-          val internalRow = InternalRow(
-            UTF8String.fromString(path),
-            DateTimeUtils.fromMillis(modificationTime),
-            length,
-            content
-          )
-
-          Iterator(requiredColumns(internalRow))
+          Iterator.single(InternalRow(values: _*))
 
 Review comment:
   Why don't project to unsafe row like previously?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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