[SPARK-58273][SQL] Do not auto-fill generated columns for by-position schema evolution inserts#57441
Closed
szehon-ho wants to merge 1 commit into
Closed
Conversation
… schema evolution inserts
HyukjinKwon
approved these changes
Jul 22, 2026
cloud-fan
approved these changes
Jul 23, 2026
cloud-fan
left a comment
Contributor
There was a problem hiding this comment.
0 blocking, 0 non-blocking, 0 nits.
The implementation is narrowly scoped, consistent with regular by-position inserts, and adequately covered.
Verification
Reviewed the ResolveOutputRelation mode selection, positional resolution and default-generation paths, catalog capability metadata stripping, regular-insert analogue, and the focused regression test. No tests were run as part of this review.
uros-b
approved these changes
Jul 23, 2026
Member
|
Thank you @szehon-ho and @HyukjinKwon @cloud-fan! |
uros-b
pushed a commit
that referenced
this pull request
Jul 23, 2026
… schema evolution inserts ### What changes were proposed in this pull request? This PR updates `TableOutputResolver` so `INSERT WITH SCHEMA EVOLUTION` by position does not auto-fill trailing generated columns. If a by-position insert omits a trailing generated column, Spark now throws the same arity mismatch error as a regular by-position insert. The PR also adds coverage that: - by-position `INSERT WITH SCHEMA EVOLUTION` rejects an omitted trailing generated column; - by-name `INSERT WITH SCHEMA EVOLUTION` with an explicit column list still auto-fills the generated column. ### Why are the changes needed? By-position writes require values for all target columns. Generated columns are special because users can omit them only through by-name writes with an explicit column list, where Spark can unambiguously identify the stored input columns used by the generation expression. Without this change, the by-position schema-evolution path could auto-fill a trailing generated column, making it inconsistent with regular by-position inserts and with Delta behavior. ### Does this PR introduce _any_ user-facing change? Yes. In the current unreleased behavior, a by-position `INSERT WITH SCHEMA EVOLUTION` could omit a trailing generated column and have Spark auto-fill it. After this change, that insert fails with `INSERT_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS`. Users can still omit generated columns with a by-name insert and an explicit column list. ### How was this patch tested? Added a regression test in `GeneratedColumnWriteSuite`. Ran: ``` MAVEN_MIRROR_URL=https://maven-proxy.cloud.databricks.com build/sbt 'sql/testOnly org.apache.spark.sql.connector.GeneratedColumnWriteSuite -- -z "INSERT WITH SCHEMA EVOLUTION by position does not auto-fill trailing generated column"' ``` ### Was this patch authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-5) Closes #57441 from szehon-ho/codex/generated-column-schema-evolution. Authored-by: Szehon Ho <szehon.apache@gmail.com> Signed-off-by: Uros Bojanic <221401595+uros-b@users.noreply.github.com> (cherry picked from commit 31f86ed) Signed-off-by: Uros Bojanic <221401595+uros-b@users.noreply.github.com>
Member
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?
This PR updates
TableOutputResolversoINSERT WITH SCHEMA EVOLUTIONby position does not auto-fill trailing generated columns. If a by-position insert omits a trailing generated column, Spark now throws the same arity mismatch error as a regular by-position insert.The PR also adds coverage that:
INSERT WITH SCHEMA EVOLUTIONrejects an omitted trailing generated column;INSERT WITH SCHEMA EVOLUTIONwith an explicit column list still auto-fills the generated column.Why are the changes needed?
By-position writes require values for all target columns. Generated columns are special because users can omit them only through by-name writes with an explicit column list, where Spark can unambiguously identify the stored input columns used by the generation expression.
Without this change, the by-position schema-evolution path could auto-fill a trailing generated column, making it inconsistent with regular by-position inserts and with Delta behavior.
Does this PR introduce any user-facing change?
Yes. In the current unreleased behavior, a by-position
INSERT WITH SCHEMA EVOLUTIONcould omit a trailing generated column and have Spark auto-fill it. After this change, that insert fails withINSERT_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS. Users can still omit generated columns with a by-name insert and an explicit column list.How was this patch tested?
Added a regression test in
GeneratedColumnWriteSuite.Ran:
Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-5)