Skip to content

[SPARK-58273][SQL] Do not auto-fill generated columns for by-position schema evolution inserts#57441

Open
szehon-ho wants to merge 1 commit into
apache:masterfrom
szehon-ho:codex/generated-column-schema-evolution
Open

[SPARK-58273][SQL] Do not auto-fill generated columns for by-position schema evolution inserts#57441
szehon-ho wants to merge 1 commit into
apache:masterfrom
szehon-ho:codex/generated-column-schema-evolution

Conversation

@szehon-ho

Copy link
Copy Markdown
Member

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)

@szehon-ho
szehon-ho requested a review from cloud-fan July 22, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants