Skip to content

Use transaction metadata in dynamic_partition_overwrite - #4221

Open
bethvourc wants to merge 1 commit into
apache:mainfrom
bethvourc:fix/dynamic-overwrite-transaction-metadata
Open

bethvourc wants to merge 1 commit into
apache:mainfrom
bethvourc:fix/dynamic-overwrite-transaction-metadata

Conversation

@bethvourc

Copy link
Copy Markdown

Closes #4192

Rationale for this change

Transaction.dynamic_partition_overwrite wrote its data files using the
committed table metadata, but built its delete filter from the transaction's
metadata. After an update_spec in the same transaction, the two disagree on
the partition spec, so the wrong rows can be deleted and new files recorded
under the wrong partition. After an in-transaction add_column, it raises
ValueError instead.

This passes self.table_metadata to _dataframe_to_data_files, matching
append, overwrite and delete.

Are these changes tested?

Yes. Two new tests cover update_spec and add_column inside a transaction.
Both fail without the fix and pass with it. The full unit suite, the Docker
integration suite and the lint hooks pass locally.

Are there any user-facing changes?

Yes, only as the bug fix: both cases now behave correctly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bethvourc

Copy link
Copy Markdown
Author

Hi @Fokko @kevinjqliu, could one of you take a look when you have time? Thanks!

@tusharchou tusharchou 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 for this. I checked it locally and it looks right to me.

What I ran

The 2 new tests pass on this branch, 6 cases across the 3 catalogs. With the one line reverted they fail. The update_spec test deletes (2, 1) and keeps (3, 2), and the add_column test raises IndexError.
I merged the branch onto main at fef852f, which now includes #4338. tests/table/test_init.py gives 184 passed. The 4 failures are the same 4 that fail on plain main in my env, because pyiceberg-core and polars are not installed.
A few extra cases inside one transaction. Each of these was wrong or raised on main and is correct with this change.
Rename the partition source column, then overwrite.
update_spec, then 2 overwrites of the same partition. Main kept all 3 rows with b = 2.
The new data file is recorded under the staged spec id.
A v1 table with add_identity.
A write property set earlier in the transaction (the compression codec) is now honoured, the same as append and overwrite.
Small things

The description says the add_column case raises ValueError. On main I get IndexError (list index out of range).
Not from this PR, but in the same function. On a v1 table, removing a partition field leaves a void transform, and the identity only check rejects it, so dynamic overwrite fails after any field removal. Happy to open an issue for that.
#4204 changes the line that builds partitions_fields, so one of the two will need a rebase.
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 after an in-transaction update_spec loses rows

2 participants