Fix TruncateTransform.satisfies_order_of for different widths (#3680) - #3854
Fix TruncateTransform.satisfies_order_of for different widths (#3680)#3854hedger9487 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a runtime AttributeError in TruncateTransform.satisfies_order_of when comparing truncate transforms with different widths by removing reliance on the unset source_type, aligning behavior with the Iceberg reference implementation.
Changes:
- Simplified
TruncateTransform.satisfies_order_ofto checkisinstance(other, TruncateTransform)and compare widths (self.width >= other.width). - Added unit tests covering width comparisons and ensuring non-truncate transforms return
False.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyiceberg/transforms.py |
Fixes satisfies_order_of to avoid accessing an uninitialized private attribute and bases ordering satisfaction on width comparison. |
tests/test_transforms.py |
Adds regression tests for truncate-width comparisons and cross-transform comparisons. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| def satisfies_order_of(self, other: Transform[S, T]) -> bool: | ||
| if self == other: | ||
| return True | ||
| elif ( |
There was a problem hiding this comment.
It doesn't appear that we use source_type anywhere after this change. Can you take this opportunity to remove it?
There was a problem hiding this comment.
Makes sense! Took this opportunity to clean up _source_type and the source_type property as well, and expanded the unit test suite to verify cross-transform comparisons and attribute cleanup.
Thanks for the review, @rambleraptor!
Closes #3680
Rationale for this change
TruncateTransform.satisfies_order_ofpreviously accessedself.source_type(andother.source_type), which raisedAttributeError: 'TruncateTransform' object has no attribute '_source_type'whenever comparing truncate transforms with different widths.Per the Iceberg spec and matching the Java reference implementation, ordering satisfaction between two truncate transforms depends purely on the width comparison (
self.width >= other.width).This PR:
TruncateTransform.satisfies_order_ofto checkisinstance(other, TruncateTransform)and compareself.width >= other.width.Are these changes tested?
Yes, added
test_truncate_satisfies_order_ofintests/test_transforms.py. All tests and pre-commit linters pass cleanly.Are there any user-facing changes?
No.