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

 ##########
 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))) {
 
 Review comment:
   Can we make it one if-else while we're here? For instance,
   
   ```scala
   val isPatternMatched = pathGlobPattern.forall(new 
GlobFilter(_).accept(fsPath))
   
   // These vals are intentionally lazy to avoid unnecessary file access via 
short-circuiting. 
   lazy val fs = fsPath.getFileSystem(broadcastedHadoopConf.value.value)
   lazy val fileStatus = fs.getFileStatus(fsPath)
   lazy val shouldNotFilterOut = filterFuncs.forall(_.apply(fileStatus))
         
   if (isPatternMatched && shouldNotFilterOut) {
     ...
     Iterator(requiredColumns(internalRow))
   } else {
     Iterator.empty[InternalRow]
   }
   ```

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to