Skip to content

fix: no panic on empty partition in register_record_batches#1627

Merged
kosiew merged 2 commits into
apache:mainfrom
fangchenli:fix/register-record-batches-empty-panic
Jul 14, 2026
Merged

fix: no panic on empty partition in register_record_batches#1627
kosiew merged 2 commits into
apache:mainfrom
fangchenli:fix/register-record-batches-empty-panic

Conversation

@fangchenli

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #1626 .

Rationale for this change

register_record_batches read the schema via unchecked partitions.0[0][0], which panics when a partition contains no record batches (e.g. the batches of an empty pyarrow table, whose to_batches() returns []).

What changes are included in this PR?

Take the schema from the first available batch across all partitions and return a clear error when there is none, mirroring the empty-table handling added for from_arrow_table in #613. A non-empty later partition now also works instead of panicking on an empty leading one.

Are there any user-facing changes?

register_record_batches now raises a catchable Python Exception on empty input instead of aborting with a Rust panic

`register_record_batches` read the schema via unchecked `partitions.0[0][0]`,
which panics when a partition contains no record batches (e.g. the batches of
an empty pyarrow table, whose `to_batches()` returns `[]`).

Take the schema from the first available batch across all partitions and return
a clear error when there is none, mirroring the empty-table handling added for
`from_arrow_table` in apache#613. A non-empty later partition now also works instead
of panicking on an empty leading one.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

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

@fangchenli,

Thanks for your contribution.
Looks good overall.
I left two small suggestions that could make the intent clearer and strengthen the regression coverage.

Comment thread crates/core/src/context.rs
Comment thread python/tests/test_context.py
- Use find_map(|p| p.first()) instead of flatten().next() to make the
  "first batch in any partition" intent clearer (per @kosiew).
- Extend regression test to also assert the empty outer partition list
  case ([]) raises the same ValueError.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@kosiew
kosiew merged commit 699e00e into apache:main Jul 14, 2026
3 checks passed
@fangchenli
fangchenli deleted the fix/register-record-batches-empty-panic branch July 14, 2026 15:54
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.

register_record_batches panics ("index out of bounds") on an empty partition

2 participants