Skip to content

Fix schema equality for empty schemas and identifier fields - #3958

Open
kevinjqliu wants to merge 3 commits into
apache:mainfrom
kevinjqliu:kevinjqliu-fix-schema-equality
Open

Fix schema equality for empty schemas and identifier fields#3958
kevinjqliu wants to merge 3 commits into
apache:mainfrom
kevinjqliu:kevinjqliu-fix-schema-equality

Conversation

@kevinjqliu

@kevinjqliu kevinjqliu commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

Fix two cases where equivalent schemas compare unequal:

  • Empty schemas are falsy because Schema defines __len__. The if not other check makes even Schema() == Schema() return False. Remove it; the existing isinstance check still rejects non-schema values.
  • Identifier field IDs are unordered. Compare them as sets so [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.

kevinjqliu and others added 2 commits September 13, 2026 15:56
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 13, 2026 23:05

Copilot AI 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.

🟢 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>
@kevinjqliu
kevinjqliu requested review from Fokko and geruh September 13, 2026 23:20

@rambleraptor rambleraptor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This seems fine to me since we always know that comparisons should be done against other Schemas.

Comment thread pyiceberg/schema.py
if len(self.columns) != len(other.columns):
return False

identifier_field_ids_is_equal = self.identifier_field_ids == other.identifier_field_ids

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I haven't dug into this at all, but what if we just stored the identifier field IDs as a set?

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.

3 participants