Skip to content

[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
apache:masterfrom
szehon-ho:codex/generated-column-schema-evolution
Closed

[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

@cloud-fan cloud-fan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

uros-b commented Jul 23, 2026

Copy link
Copy Markdown
Member

Thank you @szehon-ho and @HyukjinKwon @cloud-fan!

@uros-b uros-b closed this in 31f86ed Jul 23, 2026
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>
@uros-b

uros-b commented Jul 23, 2026

Copy link
Copy Markdown
Member

Merge Summary:

Posted by merge_spark_pr.py

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.

4 participants