ryan-johnson-databricks commented on code in PR #40885:
URL: https://github.com/apache/spark/pull/40885#discussion_r1173759666
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormat.scala:
##########
@@ -241,47 +256,74 @@ object FileFormat {
FileSourceConstantMetadataStructField(FILE_BLOCK_LENGTH, LongType,
nullable = false),
FileSourceConstantMetadataStructField(FILE_MODIFICATION_TIME,
TimestampType, nullable = false))
+ /**
+ * All [[BASE_METADATA_FIELDS]] require custom extractors because they are
derived directly from
+ * fields of the [[PartitionedFile]], and do have entries in the file's
metadata map.
+ */
+ val BASE_METADATA_EXTRACTORS: Map[String, PartitionedFile => Any] = Map(
+ FILE_PATH -> { pf: PartitionedFile => pf.toPath.toString },
+ FILE_NAME -> { pf: PartitionedFile => pf.toPath.getName },
+ FILE_SIZE -> { pf: PartitionedFile => pf.fileSize },
+ FILE_BLOCK_START -> { pf: PartitionedFile => pf.start },
+ FILE_BLOCK_LENGTH -> { pf: PartitionedFile => pf.length },
+ // The modificationTime from the file has millisecond granularity, but the
TimestampType for
+ // `file_modification_time` has microsecond granularity.
+ FILE_MODIFICATION_TIME -> { pf: PartitionedFile => pf.modificationTime *
1000 }
+ )
+
+ /**
+ * Extracts the [[Literal]] value of a file-constant metadata column from a
[[PartitionedFile]].
+ *
+ * If an extractor is available, use it. Otherwise, attempt to fetch the
value directly from the
+ * file's metadata map, returning null if not found.
+ *
+ * Raw values (including null) are automatically converted to literals as a
courtesy.
+ */
+ def getFileConstantMetadataColumnValue(
+ name: String,
+ file: PartitionedFile,
+ metadataExtractors: Map[String, PartitionedFile => Any]): Literal = {
+ val extractor = metadataExtractors.get(name).getOrElse {
+ (_: PartitionedFile).otherConstantMetadataColumnValues.get(name).orNull
Review Comment:
Agreed. I think it's already fixed locally but I didn't push yet in case
there were other comments.
--
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]