Repository navigation
Fix dynamic_partition_overwrite when PartitionSpec contains VoidTransform fields - #4509
zerafachris wants to merge 2 commits into
Conversation
rahulsmahadev
left a comment
There was a problem hiding this comment.
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.
|
Thanks @rahulsmahadev for the thorough review and catching the interaction with #4221! I've merged #4221 ( I've also updated the PR description to document the user-facing change (I don't have repository label permissions to apply the |
rahulsmahadev
left a comment
There was a problem hiding this comment.
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.
Closes #4486
Rationale for this change
When a partition field is dropped from a v1 table (or a v2 table upgraded from v1),
PartitionSpec.fieldsretains aVoidTransformfield.Transaction.dynamic_partition_overwriteiterated over allspec.fields, which caused it to:ValueError: For now dynamic overwrite does not support a table with non-identity-transform field ...whenever anyVoidTransformfield was present.VoidTransformas partitioned rather than unpartitioned.data_file.partitionrecords to only the active non-void positions when building the delete filter (which matters especially when aVoidTransformfield precedes an activeIdentityTransformfield inspec.fields, sincedata_file.partitionis positionally indexed byspec.fields).This change filters
spec.fieldsto active non-void fields(pos, field), raises the unpartitionedValueErrorif none remain, validatesIdentityTransformonly on active fields, and projectsRecord(*(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 existingVoidTransformfields.Note: This addresses a distinct failure mode in
Transaction.dynamic_partition_overwritefrom #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 aVoidTransformprecedes an active partition field)test_dynamic_partition_overwrite_all_void_partition_fields_raisestest_dynamic_partition_overwrite_after_remove_field_with_void_field_in_transaction(verifies stagedupdate_spec().remove_field(...)in the same transaction on an upgraded v2 table that already has aVoidTransformfield)Verified locally:
pytest tests/table/test_init.py -m unit: 205 passedruff checkandruff format --checkon modified files: passedAre there any user-facing changes?
Yes.
dynamic_partition_overwritenow supports tables whose partition spec containsVoidTransformfields (previously raisedValueErrorfor non-identity transform), and raisesValueError("Cannot apply dynamic overwrite on an unpartitioned table.")when all partition fields areVoidTransform.