[python] Keep reading an Avro file after a fully-filtered batch - #10128
Open
jackylee-ch wants to merge 2 commits into
Open
jackylee-ch wants to merge 2 commits into
jackylee-ch wants to merge 2 commits into
Conversation
Akash3121
reviewed
Sep 23, 2026
|
|
||
| pb = table.new_read_builder().new_predicate_builder() | ||
| read_builder = table.new_read_builder().with_filter( | ||
| pb.greater_or_equal('user_id', 2000)) |
Contributor
There was a problem hiding this comment.
Nit: With the default batch size of 1024, this threshold makes only the first batch fully filtered; the second batch already contains matching rows. Since the implementation intentionally uses a loop to support arbitrarily many consecutive empty batches, could we use 2500 here instead? With 3000 input rows, that would skip two complete batches before returning the final 500 rows and would distinguish the loop from an implementation that retries only once.
I think, the assertion should become:
read_builder = table.new_read_builder().with_filter(
pb.greater_or_equal('user_id', 2500))
result = self._read_test_table(read_builder)
self.assertEqual(
sorted(result.column('user_id').to_pylist()), list(range(2500, n)))FormatAvroReader.read_arrow_batch reads the fastavro generator batch_size rows at a time and applies the pushed-down predicate to each batch in Python. When a whole batch matched nothing it returned None, but a RecordBatchReader returns None only at end of input, and ConcatBatchReader treats None as "reader exhausted" and moves to the next file. So a filtered read of an Avro file that had a full batch (1024 rows by default) of non-matching rows silently dropped every remaining row. Loop to the next batch when a filtered batch is empty instead of returning None; return None only when the generator is exhausted. A loop rather than recursion avoids a RecursionError on long runs of filtered-out rows. The no-predicate path is unchanged.
Raise the filter threshold so a 3000-row file fully filters its first two 1024-row batches before matching, distinguishing the read loop from an implementation that only retries a single empty batch.
jackylee-ch
force-pushed
the
py-avro-filter-rows
branch
from
September 23, 2026 04:54
0ae0205 to
bb870c5
Compare
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.
Purpose
FormatAvroReader.read_arrow_batchreads the fastavro generatorbatch_size(default 1024) rows at a time and applies the pushed-down predicate in Python. When a whole batch matched nothing it returnedNone— but aRecordBatchReaderreturnsNoneonly at end of input, andConcatBatchReadertreatsNoneas "reader exhausted" and advances to the next file.So a filtered read of an Avro file with a full non-matching batch silently dropped every remaining row: an append-only
file.format = avrotable of 3000 rows read withuser_id >= 2000returns 0 rows instead of 1000 (the leading 1024-row block fails the predicate →None→ EOF).The reader now loops to the next batch on an empty filtered batch, returning
Noneonly when the generator is exhausted. A loop (not recursion) avoids aRecursionErroron long filtered runs; the no-predicate path is unchanged.format_row_readeralready handles this the same way.Tests
reader_append_only_test.test_avro_ao_reader_filter_keeps_rows_past_first_batch: a 3000-row Avro table read withuser_id >= 2000asserts the 1000 matching rows. Fails on master ([]); passes here.