Skip to content

Fix writes to partition specs with several fields on one source column - #4519

Merged
kevinjqliu merged 2 commits into
apache:mainfrom
smaheshwar-pltr:sm/partition-write-void-and-shared-source
Nov 30, 2026
Merged

kevinjqliu merged 2 commits into
apache:mainfrom
smaheshwar-pltr:sm/partition-write-void-and-shared-source

Conversation

@smaheshwar-pltr

Copy link
Copy Markdown
Contributor

Rationale for this change

Writes fail with ValueError: Cannot have redundant partitions when the partition spec has more than one field on the same column. These specs are valid, for example:

  • identity(a) and bucket[4](a), or bucket and truncate on one column.
  • On v1, after changing a field's transform. A v1 spec can't drop a field, so the old one becomes void and the spec has void(a) and bucket[4](a).

The writer pairs each partition field with its value, but then looked the field up again by its source column and raised if the column had more than one. This uses the field it already has. The lookup was only used to get the source column's type, which every field on that column shares, so other specs get the same partition values as before. Java (StructTransform), Rust (PartitionValueCalculator) and Go (newPartitionExtractionPlan) also compute each field's value separately.

Are these changes tested?

Yes. A catalog test writes to bucket + truncate and identity + bucket specs on v2 and a void + bucket spec on v1, and checks the partition values, filter pruning and rows read back. It fails without the fix.

Are there any user-facing changes?

Appends, overwrites, upserts, and deletes that rewrite files now work for these specs.

AI Disclosure: This PR was authored by Claude Code (Opus 5.5) but directed and overseen by me.

PartitionKey looked up each value's partition field by its source column
and raised "Cannot have redundant partitions" when the spec had more than
one field on that column, such as void(a) and bucket[4](a) after changing
a transform on v1, or identity(a) and bucket[4](a) on v2. Each value
already names its partition field, so use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread pyiceberg/partitioning.py
Comment on lines -473 to -475
partition_fields = self.partition_spec.source_id_to_fields_map[raw_partition_field_value.field.source_id]
if len(partition_fields) != 1:
raise ValueError(f"Cannot have redundant partitions: {partition_fields}")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the PR description for why I think it's fine to remove this check to mirror the other implementations (I've checked Java, Rust, and Go here)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

LGTM

@kevinjqliu
kevinjqliu enabled auto-merge November 30, 2026 18:28
@kevinjqliu
kevinjqliu added this pull request to the merge queue Nov 30, 2026
Merged via the queue into apache:main with commit d0e3410 Nov 30, 2026
20 checks passed
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.

2 participants