Return schema-preserving empty table on empty read result#9
Merged
xando merged 2 commits intoJun 10, 2026
Merged
Conversation
When `row_restrictions` (or the table itself) matches no rows, BigQuery returns zero streams but still provides the table schema. Previously this crashed: the Python engine hit `assert self.streams`, and both engines fed an empty iterator into `pa.concat_tables`, raising `ArrowInvalid: Must pass at least one table`. Now `read_table` and `read_query` fall back to `reader.schema.empty_table()`, returning a zero-row table that preserves the BigQuery schema for both the python and rust engines.
Replace the mock-based unit tests with integration tests that write a real table and read it back with a `row_restrictions` matching no rows, asserting a zero-row table with the preserved schema for both the python and rust engines, on read_table and read_query.
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.
Summary
When
row_restrictions(or the source table) matches no rows, BigQuery's Storage Read API returns zero streams but still provides the table schema. The current code did not handle this:engine="python"crashed onassert self.streams, "No streams to read, Table might be empty".pa.concat_tables(...), raising the unhelpfulArrowInvalid: Must pass at least one table.This PR makes an empty result set return a zero-row
pa.Tablethat preserves the BigQuery schema, for both engines:reader._enter_pythonno longer asserts on empty streams; it starts no workers and keepsself.schemafrom the read session._next_pythonstops immediately when there are no streams, and the worker-split loop is skipped to avoid aZeroDivisionErrorinto_split.read_table/read_querycollect batches and fall back toreader.schema.empty_table()when nothing is returned.This keeps downstream code working (columns are always present) instead of crashing or silently dropping the schema.
Test plan
tests/unit/test_read_empty.pyadded, covering:schemaread_tablereturns a 0-row table with the correct schemaread_tablereturns a 0-row table with the correct schemaruff checkpassespytest tests/unitpasses (34 passed)