Skip to content

Check partition names against the current schema when adding a spec - #4266

Open
Rahul-cs50 wants to merge 1 commit into
apache:mainfrom
Rahul-cs50:fix/4198-update-spec-stale-name-check
Open

Rahul-cs50 wants to merge 1 commit into
apache:mainfrom
Rahul-cs50:fix/4198-update-spec-stale-name-check

Conversation

@Rahul-cs50

Copy link
Copy Markdown

Closes #4198

Rationale for this change

UpdateSpec checks each new partition name against the schema it was loaded with, using the check from #2305. Its commit asserts only the last assigned partition id and the default spec id. Suppose another writer adds a column xb in between. A stale handle can then add a partition field named xb, and the commit goes through. Java then refuses to load that metadata (Cannot create identity partition sourced from different field in schema: xb).

This change runs validate_partition_name again when AddPartitionSpecUpdate is applied, against the schema of the metadata the spec is being added to. On a catalog that applies updates to the latest metadata at commit time, the stale update_spec now raises the same ValueError it raises without the concurrent change. The schema-side check in UpdateSchema already validates every partition spec in this way.

The issue also mentions the opposite order: a stale update_schema().add_column("xb") after another writer added partition field xb. That is the same problem, but on the schema update path. I kept it out of this PR so this one stays small, and can follow up if wanted.

Are these changes tested?

Yes. test_concurrent_update_spec_checks_names_against_current_schema in tests/catalog/test_catalog_behaviors.py follows the issue's steps:

  • One handle adds column xb.
  • A stale handle then adds a bucket partition field named xb.
  • The test expects the ValueError, and checks that the table is still unpartitioned.

It fails on main (no error is raised) and passes with this change, for all catalog fixtures. Unit tests (tests/ without integration and cloud suites): 4501 passed; the 4 failures are Kerberos tests in tests/catalog/test_hive.py that fail the same way on main in my environment. ruff check and ruff format --check are clean.

Are there any user-facing changes?

A stale update_spec() that adds a partition field whose name now clashes with a column in the current schema raises ValueError at commit. Before, it wrote metadata that Java refuses to load.

UpdateSpec checks new partition names against the schema it was loaded
with. If another writer added a column with the same name in between,
the commit still went through and wrote metadata Java refuses to load.
Check the names again when the spec is applied to the current metadata.

Closes apache#4198
Copilot AI balanced review requested due to automatic review settings November 2, 2026 18:00

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
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.

A stale update_spec adds a partition field named like a column another writer added, which Java cannot load

2 participants