Yaohua628 commented on a change in pull request #34575:
URL: https://github.com/apache/spark/pull/34575#discussion_r756509948



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileScanRDD.scala
##########
@@ -103,6 +116,135 @@ class FileScanRDD(
         context.killTaskIfInterrupted()
         (currentIterator != null && currentIterator.hasNext) || nextIterator()
       }
+
+      ///////////////////////////
+      // FILE METADATA METHODS //
+      ///////////////////////////
+
+      // whether a metadata column exists and it is a `MetadataAttribute`
+      private lazy val hasMetadataAttribute: Boolean = {
+        metadataStruct.exists {
+          case MetadataAttribute(_) => true
+          case _ => false
+        }
+      }
+
+      // metadata struct unsafe row, will only be updated when the current 
file is changed
+      @volatile private var metadataStructUnsafeRow: UnsafeRow = _
+      // metadata generic row, will only be updated when the current file is 
changed
+      @volatile private var metadataStructGenericRow: Row = _
+      // an unsafe joiner to join an unsafe row with the metadata unsafe row
+      lazy private val unsafeRowJoiner =
+        if (hasMetadataAttribute)
+          GenerateUnsafeRowJoiner.create(requiredSchema, 
Seq(metadataStruct.get).toStructType)
+
+      // Create a off/on heap WritableColumnVector
+      private def createColumnVector(numRows: Int, dataType: DataType): 
WritableColumnVector = {
+        if (offHeapColumnVectorEnabled) {
+          new OffHeapColumnVector(numRows, dataType)
+        } else {
+          new OnHeapColumnVector(numRows, dataType)
+        }
+      }
+
+      /**
+       * For each partitioned file, metadata columns for each record in the 
file are exactly same.
+       * Only update metadata columns when `currentFile` is changed.
+       */
+      private def updateMetadataStruct(): Unit = {
+        if (hasMetadataAttribute) {
+          val meta = metadataStruct.get
+          if (currentFile == null) {
+            metadataStructUnsafeRow = new UnsafeRow(1)
+            metadataStructGenericRow = new GenericRow(1)
+          } else {
+            // make an generic row
+            assert(meta.dataType.isInstanceOf[StructType])
+            metadataStructGenericRow = Row.fromSeq(
+              meta.dataType.asInstanceOf[StructType].names.map {
+                case FILE_PATH => UTF8String.fromString(new 
File(currentFile.filePath).toString)

Review comment:
       @cloud-fan that's actually a good point - I saw three slashes in 
`currentFile.filePath`
   ```
   file:///Users/...
   ```
   I guess it's because the host is local, so it's just dropped.
   
   Do you think it is OK? My tests will actually be broken since I get the file 
path from `new File(...).toURI.toString`, is this something I should fix in my 
test or the code? thanks!




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to