Gengliang Wang created SPARK-27356:
--------------------------------------

             Summary: File source V2: return actual schema in method 
`FileScan.readSchema`
                 Key: SPARK-27356
                 URL: https://issues.apache.org/jira/browse/SPARK-27356
             Project: Spark
          Issue Type: Improvement
          Components: SQL
    Affects Versions: 3.0.0
            Reporter: Gengliang Wang


The method `Scan.readSchema` returns the actual schema of this data source 
scan. 
In the current file source V2 framework, the schema is not returned correctly. 
The result should be `readDataSchema + partitionSchema`, while the framework 
returns the schema which is pushed down in 
`SupportsPushDownRequiredColumns.requiredSchema`.
This is normally OK. But if there are overlap columns between `dataSchema` and 
`partitionSchema`, the result of row-base scan will be wrong. The actual schema 
should be 
`dataSchema - overlapSchema + partitionSchema`, which is different from from 
the pushed down `requiredSchema`.

This PR is to:
1. Bug fix: fix the corner case that `dataSchema` overlaps with 
`partitionSchema`.
2. Improvement: Prune partition column values if part of the partition columns 
are not required.
3. Behavior change: To make it simple, the schema of `FileTable` is `dataSchema 
- overlapSchema + partitionSchema`, instead of mixing data schema and 
partitionSchema (see `PartitioningUtils.mergeDataAndPartitionSchema`)
For example, the data schema is [a,b,c], the partition schema is  [b,d],
In V1, the schema of `HadoopFsRelation` is [a, b, c, d]
in File source V2 , the schema of `FileTable` is [a, c, b, d]
Putting all the partition columns to the end of table schema is more 
reasonable. Also, when there is `select *` operation and there is no schema 
pruning, the schema of `FileTable` and `FileScan` still matches.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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

Reply via email to