Fix schema equality for empty schemas and identifier fields - #3958
Open
kevinjqliu wants to merge 3 commits into
Open
Fix schema equality for empty schemas and identifier fields#3958kevinjqliu wants to merge 3 commits into
kevinjqliu wants to merge 3 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes are covered by regression tests, with no unresolved blocking issues.
Pull request overview
Fixes Schema equality for empty schemas and unordered identifier field IDs.
Changes:
- Removes truthiness-based rejection of empty schemas.
- Compares identifier field IDs as sets.
- Adds regression tests.
File summaries
| File | Description |
|---|---|
tests/test_schema.py |
Adds equality regression tests. |
pyiceberg/schema.py |
Updates schema equality logic. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
rambleraptor
approved these changes
Sep 14, 2026
rambleraptor
left a comment
Collaborator
There was a problem hiding this comment.
This seems fine to me since we always know that comparisons should be done against other Schemas.
rambleraptor
approved these changes
Sep 14, 2026
| if len(self.columns) != len(other.columns): | ||
| return False | ||
|
|
||
| identifier_field_ids_is_equal = self.identifier_field_ids == other.identifier_field_ids |
Collaborator
There was a problem hiding this comment.
I haven't dug into this at all, but what if we just stored the identifier field IDs as a set?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Fix two cases where equivalent schemas compare unequal:
Schemadefines__len__. Theif not othercheck makes evenSchema() == Schema()returnFalse. Remove it; the existingisinstancecheck still rejects non-schema values.[1, 2]and[2, 1]are equal, while different sets remain unequal.This matches Java’s
Schema.sameSchema(): compare fields in order and identifier IDs as sets, ignoring the schema ID.Are these changes tested?
Yes, 331 schema tests pass, including focused regressions for both cases.
Are there any user-facing changes?
Empty schemas and schemas with reordered identifier IDs now compare equal. Field comparison is unchanged.