Skip to content

Fix dynamic_partition_overwrite when PartitionSpec contains VoidTransform fields - #4509

Open
zerafachris wants to merge 2 commits into
apache:mainfrom
zerafachris:fix/dynamic-partition-overwrite-void-transform
Open

zerafachris wants to merge 2 commits into
apache:mainfrom
zerafachris:fix/dynamic-partition-overwrite-void-transform

Conversation

@zerafachris

@zerafachris zerafachris commented Nov 28, 2026 •

Copy link
Copy Markdown

Closes #4486

Rationale for this change

When a partition field is dropped from a v1 table (or a v2 table upgraded from v1), PartitionSpec.fields retains a VoidTransform field.
Transaction.dynamic_partition_overwrite iterated over all spec.fields, which caused it to:

  1. Raise ValueError: For now dynamic overwrite does not support a table with non-identity-transform field ... whenever any VoidTransform field was present.
  2. Treat a partition spec whose fields are all VoidTransform as partitioned rather than unpartitioned.
  3. Fail to project data_file.partition records to only the active non-void positions when building the delete filter (which matters especially when a VoidTransform field precedes an active IdentityTransform field in spec.fields, since data_file.partition is positionally indexed by spec.fields).

This change filters spec.fields to active non-void fields (pos, field), raises the unpartitioned ValueError if none remain, validates IdentityTransform only on active fields, and projects Record(*(data_file.partition[pos] for pos, _ in non_void_fields)) for the partition overwrite filter. It also incorporates #4221 (self.table_metadata) so staged spec changes in the same transaction are respected alongside existing VoidTransform fields.

Note: This addresses a distinct failure mode in Transaction.dynamic_partition_overwrite from #4204 (which resolves nested column paths in _build_partition_predicate).

Are these changes tested?

Yes. Added unit tests in tests/table/test_init.py:

  • test_dynamic_partition_overwrite_with_void_partition_field (both v1 and upgraded-to-v2 tables)
  • test_dynamic_partition_overwrite_with_leading_void_partition_field (verifies positional projection when a VoidTransform precedes an active partition field)
  • test_dynamic_partition_overwrite_all_void_partition_fields_raises
  • test_dynamic_partition_overwrite_after_remove_field_with_void_field_in_transaction (verifies staged update_spec().remove_field(...) in the same transaction on an upgraded v2 table that already has a VoidTransform field)

Verified locally:

  • pytest tests/table/test_init.py -m unit: 205 passed
  • ruff check and ruff format --check on modified files: passed

Are there any user-facing changes?

Yes. dynamic_partition_overwrite now supports tables whose partition spec contains VoidTransform fields (previously raised ValueError for non-identity transform), and raises ValueError("Cannot apply dynamic overwrite on an unpartitioned table.") when all partition fields are VoidTransform.

@rahulsmahadev rahulsmahadev 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.

Thanks @zerafachris! The new tests fail on main and pass here, and void fields in any position gave the expected rows on v1 and upgraded v2 tables.

I'd recommend also taking the one-line change from #4221 (or landing it first): the positions come from the transaction's spec, but the files are still written with the committed one. If the same transaction changes the spec, a row outside the partition is deleted, where main raised. On a v1 table with identity on p, q, r and rows (A, X, U, 1), (B, Y, null, 2), (C, Z, V, 3):

tbl.update_spec().remove_field("q").commit()  # q becomes void
tbl.transaction().upgrade_table_version(2).commit_transaction()
with tbl.transaction() as tx:
    tx.update_spec().remove_field("p").commit()
    tx.dynamic_partition_overwrite(pa.table({"p": ["N"], "q": ["Q"], "r": ["U"], "id": [100]}))
# ids [1, 3, 100]: id 2 (r = null) is deleted and id 1 (r = U) kept; expected [2, 3, 100]

A smaller one: these tables used to raise, so this is a user-facing change; worth saying in the description, with the changelog label.

@zerafachris

Copy link
Copy Markdown
Author

Thanks @rahulsmahadev for the thorough review and catching the interaction with #4221!

I've merged #4221 (31cda8ed) to resolve the merge conflict and pick up the self.table_metadata fix, and added test_dynamic_partition_overwrite_after_remove_field_with_void_field_in_transaction covering the exact staged remove_field + existing VoidTransform scenario you described (verified ids == [2, 3, 100]).

I've also updated the PR description to document the user-facing change (I don't have repository label permissions to apply the changelog label myself, so a maintainer will need to add it). Re-ran pytest tests/table/test_init.py -m unit (205 passed) and ruff check / ruff format --check.

@rahulsmahadev rahulsmahadev 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.

Thanks @zerafachris, the changes look right to me. On d3705e7, the staged remove_field repro now returns ids [2, 3, 100], the new test fails on main and also catches a revert of the #4221 line, and void fields first, middle, last and in pairs still give the expected rows on v1 and upgraded v2 tables. LGTM.

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.

dynamic_partition_overwrite raises on v1 tables after a partition field is removed

2 participants