[SPARK-55690] Schema evolution in DSv2 AppendData, OverwriteByExpression, OverwritePartitionsDynamic#54488
Open
johanl-db wants to merge 6 commits intoapache:masterfrom
Open
[SPARK-55690] Schema evolution in DSv2 AppendData, OverwriteByExpression, OverwritePartitionsDynamic#54488johanl-db wants to merge 6 commits intoapache:masterfrom
johanl-db wants to merge 6 commits intoapache:masterfrom
Conversation
szehon-ho
reviewed
Feb 26, 2026
Member
szehon-ho
left a comment
There was a problem hiding this comment.
Thanks, I think this is a great pr! The tests coverage can be improved on various cases, but functionally its a good change:
eg
- INSERT OVERWRITE with PartitionOverwriteMode.DYNAMIC + schema evolution
- Case-insensitive column name matching
- Static partition overwrite with schema evolution
- Table without AUTOMATIC_SCHEMA_EVOLUTION capability should no-op
etc
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSchemaEvolution.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSchemaEvolution.scala
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSchemaEvolution.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSchemaEvolution.scala
Outdated
Show resolved
Hide resolved
szehon-ho
reviewed
Feb 27, 2026
Member
szehon-ho
left a comment
There was a problem hiding this comment.
This looks good to me!
suggestion: add tests like:
- type evolution
- 2 level structs
- non-partitioned table
- constraints
Also do we run the same tests Dataframe API? (I think we only test with SQL?)
| updates ++ adds | ||
| } | ||
|
|
||
| def toFieldMap(fields: Array[StructField]): Map[String, StructField] = { |
| sql(s"CREATE TABLE $t1 (id bigint, data string) USING $v2Format") | ||
| checkError( | ||
| exception = intercept[AnalysisException] { | ||
| doInsert(t1, Seq((2L, "b", true)).toDF("id", "data", "active")) |
szehon-ho
approved these changes
Feb 28, 2026
Member
szehon-ho
left a comment
There was a problem hiding this comment.
lgtm! cc @aokolnychyi @cloud-fan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Adds support for schema evolution during INSERT operations (AppendData, OverwriteByExpression, OverwritePartitionsDynamic)
When the table reports capability
AUTOMATIC_SCHEMA_EVOLUTION, a new analyzer ruleResolveInsertSchemaEvolutioncollects new columns and nested fields present in the source query but not in the table schema, and adds them to the target table by callingcatalog.alterTable()Identifying new columns/fields respects the resolution semantics of INSERT operations: matching fields by-name vs by-position.
This builds on previous from @szehon-ho , in particular #51698.
The first two commits move this previous code around to reuse it, the core of the implementation is in the third commit.
Why are the changes needed?
The
WITH SCHEMA EVOLUTIONsyntax for SQL inserts was added recently: #53732. This actually implements schema evolution behind this syntax.Does this PR introduce any user-facing change?
Yes, when the
WITH SCHEMA EVOLUTIONclause is specified in SQL INSERT operations, new columns and nested fields in the source data will be added to the target table - assuming the data source supports schema evolution (capability AUTOMATIC_SCHEMA_EVOLUTION):How was this patch tested?
Added basic testing in
DataSourceV2SQLSuite.Integrated with Delta and ran extensive Delta test harness for schema evolution against this implementation.
See delta-io/delta#6140. A number of expected failures for tests that would need to be updated on Delta side (different error class returned, negative tests checking something specifically doesn't work if a fix is disabled, ..)