Skip to content

Write to partition specs with several fields on one source column - #4537

Closed
DG47 wants to merge 1 commit into
apache:mainfrom
DG47:fix/partition-key-shared-source
Closed

DG47 wants to merge 1 commit into
apache:mainfrom
DG47:fix/partition-key-shared-source

Conversation

@DG47

@DG47 DG47 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Closes #4536

Rationale for this change

PartitionKey.partition looked up each partition field by its source column and raised Cannot have redundant partitions when the spec had more than one field on that column. Specs like bucket(id) plus truncate(id) are valid, and Java and Spark write them. A format v1 table also ends up with one whenever a partition field on a column is replaced, for example to change the bucket count, because the removed field stays in the spec as a void transform of the same column. Appends, overwrites and deletes that rewrite part of a data file all failed on these tables.

Each PartitionFieldValue already carries the partition field it was computed for, so PartitionKey.partition now uses that field instead of looking it up by source column. Specs with one field per source column produce the same partition records as before.

An earlier attempt at this, #4092, was closed by the stale bot without review.

Are these changes tested?

Yes. test_append_to_table_with_multiple_partition_fields_on_one_column in tests/catalog/test_catalog_behaviors.py runs against the memory and SQL catalogs. It appends to a table partitioned by bucket(4, id) and truncate(10, id) and checks the partition values and a filtered scan. It then changes the bucket count of a format v1 table, appends again, and checks the new partition values (null for the void field) and the rows. The test fails on main with the ValueError and passes with this change.

make lint passes, and make test gives 4965 passed, 6 skipped, 129 deselected.

Are there any user-facing changes?

Yes. Writes to tables with more than one partition field on the same column now succeed instead of raising ValueError.

PartitionKey.partition looked up each partition field by its source column
and raised "Cannot have redundant partitions" when the spec had more than
one field on that column. Specs like bucket(id) plus truncate(id) are valid,
and a format v1 table gets one whenever a partition field on a column is
replaced, because the removed field stays as a void transform. Appends,
overwrites and deletes to such tables failed. Each PartitionFieldValue
already carries its partition field, so use it directly.

@smaheshwar-pltr smaheshwar-pltr 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.

Hey @DG47 thanks for looking into this and putting up the issue 🙏 I think we have #4519 already for this or is there a problem with that approach?

@DG47

DG47 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

You're right, #4519 is the same fix and it came first, so I'm closing this one. #4536 has the reproduction if you want #4519 to close it.

@DG47 DG47 closed this Nov 30, 2026
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.

Writes fail with "Cannot have redundant partitions" when a partition spec has two fields on the same column

2 participants