Skip to content

Conversation

@szehon-ho
Copy link
Member

@szehon-ho szehon-ho commented Dec 6, 2025

What changes were proposed in this pull request?

Keep existing behavior for MERGE INTO without SCHEMA EVOLUTION clause for UPDATE SET * and INSERT * as well as UPDATE struct or INSERT struct, to throw exception if the source and target schemas are not exactly the same.

Why are the changes needed?

As @aokolnychyi tested this feature, he mentioned that as of Spark 4.1 the behavior is changed for MERGE INTO but without SCHEMA EVOLUTION clause.

In particular:

Initially, I thought its a good improvement of MERGE INTO and is not related to SCHEMA EVOLUTION exactly because the schema is not altered. But Anton has a good point that it may be a surprise to some user. So it may be better for now to be more conservative and keep the exact same behavior for without SCHEMA EVOLUTION clause.

Note: this behavior is still enabled if SCHEMA EVOLUTION is specified, as the user then is more explicit about the decision.

Does this PR introduce any user-facing change?

No, this keeps behavior exactly the same as 4.0 without SCHEMA EVOLUTION clause.

How was this patch tested?

Added a test and changed existing test output to expect the exception if SCHEMA EVOLUTION is not specified.

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

No

@github-actions github-actions bot added the SQL label Dec 6, 2025
@szehon-ho szehon-ho changed the title Spark 54595 reapply [SPARK-54595][SQL][Follow-up] Keep existing behavior of MERGE INTO without SCHEMA EVOLUTION clause Dec 6, 2025
@dongjoon-hyun dongjoon-hyun changed the title [SPARK-54595][SQL][Follow-up] Keep existing behavior of MERGE INTO without SCHEMA EVOLUTION clause [SPARK-54595][SQL] Keep existing behavior of MERGE INTO without SCHEMA EVOLUTION clause Dec 6, 2025
@dongjoon-hyun
Copy link
Member

dongjoon-hyun commented Dec 6, 2025

Thank you, but this PR seems to break other test cases again, @szehon-ho .

Please make the CI happy.

@dongjoon-hyun
Copy link
Member

Gentle ping, @szehon-ho .

@dongjoon-hyun
Copy link
Member

Gentle ping once more, @szehon-ho . 😄

@szehon-ho
Copy link
Member Author

Ah, i will fix this today.

@szehon-ho
Copy link
Member Author

@dongjoon-hyun its fixed now, thanks!

@dongjoon-hyun
Copy link
Member

Thank you always, @szehon-ho !

dongjoon-hyun pushed a commit that referenced this pull request Dec 8, 2025
…A EVOLUTION clause

### What changes were proposed in this pull request?
Keep existing behavior for MERGE INTO without SCHEMA EVOLUTION clause for UPDATE SET * and INSERT * as well as UPDATE struct or INSERT struct, to throw exception if the source and target schemas are not exactly the same.

### Why are the changes needed?
As aokolnychyi  tested this feature, he mentioned that as of Spark 4.1 the behavior is changed for MERGE INTO but without SCHEMA EVOLUTION clause.

In particular:

- Source has less columns/nested fields than target => we fill with NULL or DEFAULT for inserts, and existing value for Update. (though we disabled for nested structs by default in [[SPARK-54525](https://issues.apache.org/jira/browse/SPARK-54525))](https://github.com/apache/spark/pull/53229)
- Source has more columns/fields than target => we drop the extra fields.

Initially, I thought its a good improvement of MERGE INTO and is not related to SCHEMA EVOLUTION exactly because the schema is not altered. But Anton has a good point that it may be a surprise to some user. So it may be better for now to be more conservative and keep the exact same behavior for without SCHEMA EVOLUTION clause.

Note: this behavior is still enabled if SCHEMA EVOLUTION is specified, as the user then is more explicit about the decision.

### Does this PR introduce _any_ user-facing change?
No, this keeps behavior exactly the same as 4.0 without SCHEMA EVOLUTION clause.

### How was this patch tested?
Added a test and changed existing test output to expect the exception if SCHEMA EVOLUTION is not specified.

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

Closes #53363 from szehon-ho/SPARK-54595-reapply.

Authored-by: Szehon Ho <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit 70ee0e1)
Signed-off-by: Dongjoon Hyun <[email protected]>
@dongjoon-hyun
Copy link
Member

Merged to master/4.1 for Apache Spark 4.1.0.

xu20160924 pushed a commit to xu20160924/spark that referenced this pull request Dec 9, 2025
…A EVOLUTION clause

### What changes were proposed in this pull request?
Keep existing behavior for MERGE INTO without SCHEMA EVOLUTION clause for UPDATE SET * and INSERT * as well as UPDATE struct or INSERT struct, to throw exception if the source and target schemas are not exactly the same.

### Why are the changes needed?
As aokolnychyi  tested this feature, he mentioned that as of Spark 4.1 the behavior is changed for MERGE INTO but without SCHEMA EVOLUTION clause.

In particular:

- Source has less columns/nested fields than target => we fill with NULL or DEFAULT for inserts, and existing value for Update. (though we disabled for nested structs by default in [[SPARK-54525](https://issues.apache.org/jira/browse/SPARK-54525))](https://github.com/apache/spark/pull/53229)
- Source has more columns/fields than target => we drop the extra fields.

Initially, I thought its a good improvement of MERGE INTO and is not related to SCHEMA EVOLUTION exactly because the schema is not altered. But Anton has a good point that it may be a surprise to some user. So it may be better for now to be more conservative and keep the exact same behavior for without SCHEMA EVOLUTION clause.

Note: this behavior is still enabled if SCHEMA EVOLUTION is specified, as the user then is more explicit about the decision.

### Does this PR introduce _any_ user-facing change?
No, this keeps behavior exactly the same as 4.0 without SCHEMA EVOLUTION clause.

### How was this patch tested?
Added a test and changed existing test output to expect the exception if SCHEMA EVOLUTION is not specified.

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

Closes apache#53363 from szehon-ho/SPARK-54595-reapply.

Authored-by: Szehon Ho <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants