Skip to content

Commit

Permalink
[SPARK-48308][CORE] Unify getting data schema without partition colum…
Browse files Browse the repository at this point in the history
…ns in FileSourceStrategy

### What changes were proposed in this pull request?
Compute the schema of the data without partition columns only once in FileSourceStrategy.

### Why are the changes needed?
In FileSourceStrategy, the schema of the data excluding partition columns is computed 2 times in a slightly different way, using an AttributeSet (`partitionSet`) and using the attributes directly (`partitionColumns`)
These don't have the exact same semantics, AttributeSet will only use expression ids for comparison while comparing with the actual attributes will use the name, type, nullability and metadata. We want to use the former here.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Existing tests

### Was this patch authored or co-authored using generative AI tooling?
No

Closes apache#46619 from johanl-db/reuse-schema-without-partition-columns.

Authored-by: Johan Lasperas <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
  • Loading branch information
johanl-db authored and cloud-fan committed May 16, 2024
1 parent 3d3d18f commit 57948c8
Showing 1 changed file with 1 addition and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,8 @@ object FileSourceStrategy extends Strategy with PredicateHelper with Logging {
val requiredExpressions: Seq[NamedExpression] = filterAttributes.toSeq ++ projects
val requiredAttributes = AttributeSet(requiredExpressions)

val readDataColumns = dataColumns
val readDataColumns = dataColumnsWithoutPartitionCols
.filter(requiredAttributes.contains)
.filterNot(partitionColumns.contains)

// Metadata attributes are part of a column of type struct up to this point. Here we extract
// this column from the schema and specify a matcher for that.
Expand Down

0 comments on commit 57948c8

Please sign in to comment.