ryan-johnson-databricks commented on code in PR #40885:
URL: https://github.com/apache/spark/pull/40885#discussion_r1175437133


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormat.scala:
##########
@@ -203,6 +203,21 @@ trait FileFormat {
    * method. Technically, a file format could choose suppress them, but that 
is not recommended.
    */
   def metadataSchemaFields: Seq[StructField] = FileFormat.BASE_METADATA_FIELDS
+
+  /**
+   * The extractors to use when deriving file-constant metadata columns for 
this file format.
+   *
+   * By default, the value of a file-constant metadata column is obtained by 
looking up the column's
+   * name in the file's metadata column value map. However, implementations 
can override this method
+   * in order to provide an extractor that has access to the entire 
[[PartitionedFile]] when
+   * deriving the column's value.
+   *
+   * NOTE: Extractors are lazy, invoked only if the query actually selects 
their column at runtime.
+   *
+   * See also [[FileFormat.getFileConstantMetadataColumnValue]].
+   */
+  def fileConstantMetadataExtractors: Map[String, PartitionedFile => Any] =

Review Comment:
   I made a dummy PR https://github.com/apache/spark/pull/40930 to show what 
the other approach actually looks like. I still think it is uglier code for 
everyone involved, with no benefit to safety, but at least this way we have 
something concrete to compare.
   
   The change for the other PR vs master is:
   ```
    
sql/core/src/main/scala/org/apache/spark/sql/execution/DataSourceScanExec.scala 
                             |  33 +++++++++++++---------------
    
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormat.scala
                          | 145 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------
    
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileScanRDD.scala
                         |  70 
+++++++++++++++--------------------------------------------
    
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/PartitioningAwareFileIndex.scala
          |  10 ++++-----
    
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetFileFormat.scala
           |   4 ++--
    
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/FileSourceCustomMetadataStructSuite.scala
 |  71 ++++++++++++++++++++++++++++++++++++++++++++++++------------
    6 files changed, 196 insertions(+), 137 deletions(-)
   ```
   
   The change of this PR vs. master touches fewer files and is ~50LoC smaller:
   ```
    
sql/core/src/main/scala/org/apache/spark/sql/execution/DataSourceScanExec.scala 
                             |  33 +++++++++++++++------------------
    
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormat.scala
                          | 102 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
    
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileScanRDD.scala
                         |  70 
+++++++++++++++++-----------------------------------------------------
    
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/PartitioningAwareFileIndex.scala
          |  10 +++++-----
    
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/FileSourceCustomMetadataStructSuite.scala
 |  35 ++++++++++++++++++++++++++++++++++-
    5 files changed, 143 insertions(+), 107 deletions(-)
   ```
   
   The other PR vs. this one is changes 3 files and ~100LoC:
   ```
    
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormat.scala
                          | 99 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------
    
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetFileFormat.scala
           |  4 ++--
    
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/FileSourceCustomMetadataStructSuite.scala
 | 70 ++++++++++++++++++++++++++++++++++++++++------------------------------
    3 files changed, 98 insertions(+), 75 deletions(-)
   ```



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