Skip to content

[python] Skip empty batches when advancing merge readers - #9820

Open
wangzhigang1999 wants to merge 1 commit into
apache:masterfrom
wangzhigang1999:fix/python-merge-reader-empty-batch
Open

wangzhigang1999 wants to merge 1 commit into
apache:masterfrom
wangzhigang1999:fix/python-merge-reader-empty-batch

Conversation

@wangzhigang1999

Copy link
Copy Markdown
Contributor

Purpose

Fixes #9819.

Fix AttributeError: 'NoneType' object has no attribute 'key' in primary-key merge reads when an input reader returns an empty batch after a non-empty batch.

Change Element.update() to skip empty batches until it finds a record or reaches EOF. Return True only when a record is available, and close the reader at EOF.

Tests

Add one regression test with two sorted inputs, including consecutive empty batches between records and before EOF. Assert merged output, deduplication, and reader closure. The test fails with the reported exception on the unchanged baseline and passes with this fix.

Local validation after rebasing onto 43e9ad701ebee6d9af8316f35533f4d0836a1fc0, with Python 3.12.6 and PyArrow 19.0.1:

  • Real local-file reproduction: full scan remains at 6,144 rows; filtered scan returns the expected four rows and values.
  • All 59 selected tests passed: the new regression and existing sequence-field, primary-key reader, predicate reader, and merge-engine dispatch tests.
  • Changed-file flake8, license headers, and git diff --check passed.

The full CI matrix has not been run locally.

Copilot AI lite review requested due to automatic review settings September 14, 2026 11:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved blocking issues were identified, and regression coverage is included.

Pull request overview

Fixes Python primary-key merge reads by skipping empty batches until a record or EOF.

Changes:

  • Handles consecutive empty batches and closes readers at EOF.
  • Adds regression coverage for ordering, deduplication, and reader closure.
File summaries
File Description
paimon-python/pypaimon/tests/test_sort_merge_reader.py Adds regression coverage for empty-batch transitions.
paimon-python/pypaimon/read/reader/sort_merge_reader.py Safely skips empty batches during merge advancement.
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.

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.

[Bug] [python] Primary-key merge reader fails when advancing to an empty batch

2 participants