Skip to content

Fix dynamic_partition_overwrite when PartitionSpec contains VoidTransform fields - #4509

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

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

Conversation

@zerafachris

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.

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

Verified locally:

  • pytest tests/table/ tests/catalog/test_catalog_behaviors.py -m unit: 1037 passed
  • pytest tests/ -m unit --ignore=tests/integration --ignore=tests/avro/test_decoder.py --ignore=tests/avro/test_reader.py --ignore=tests/avro/test_resolver.py --ignore=tests/catalog/test_hive.py: 4721 passed, 6 skipped, 129 deselected
  • ruff check and ruff format --check on modified files: passed

Are there any user-facing changes?

No.

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

1 participant