cloud-fan commented on a change in pull request #34575:
URL: https://github.com/apache/spark/pull/34575#discussion_r755183339



##########
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(

Review comment:
       And does `metadataStructGenericRow` need to be a class member? Seems can 
be a local variable.




-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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

Reply via email to