Skip to content

[python] Fix RecursionError when reading a shard or slice of a large file - #10113

Open
jackylee-ch wants to merge 1 commit into
apache:masterfrom
jackylee-ch:py-shard-reader-recursion
Open

jackylee-ch wants to merge 1 commit into
apache:masterfrom
jackylee-ch:py-shard-reader-recursion

Conversation

@jackylee-ch

Copy link
Copy Markdown
Contributor

Purpose

ShardBatchReader.read_arrow_batch skips each out-of-range batch by recursively calling itself, so recursion depth grows one per skipped batch. A with_shard/with_slice read whose range sits deep in a data file then overflows the stack with RecursionError: the pyarrow reader yields 1024-row batches by default, so a slice starting ~1M rows in skips >1000 batches (Python's recursion limit). A slice covering only the head of a large file hits it too — the batches after end_pos are drained the same recursive way.

The fix iterates over skipped batches with a while loop, matching ConcatBatchReader and ApplyDeletionVectorReader. Behavior is otherwise unchanged.

Tests

shard_batch_reader_test: 2000 single-row batches, slice (1999, 2000) — fails on master with RecursionError, passes here. Two more cases cover range filtering ([2,5)) and the straddle branches ([2,9) over 4-row batches).

Written with Claude Code; verification is mine.

…file

ShardBatchReader.read_arrow_batch skipped each out-of-range batch by
recursively calling itself, so recursion depth grows one per skipped batch. A
with_shard/with_slice read whose range sits deep in a data file then overflows
the stack with RecursionError: the pyarrow reader yields 1024-row batches by
default, so a slice starting ~1M rows into a file skips more than 1000 batches
(Python's default recursion limit). A slice covering only the head of a large
file hits it too, because the trailing batches after end_pos are drained the
same recursive way before the reader returns None.

Iterate over skipped batches with a while loop instead, matching the pattern
already used by ConcatBatchReader and ApplyDeletionVectorReader. Behavior is
otherwise unchanged.
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.

1 participant