fix: table iterator should not use bqstorage when page_size is not None by chelsea-lin · Pull Request #2154 · googleapis/python-bigquery · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

fix: table iterator should not use bqstorage when page_size is not None #2154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,11 @@ def total_bytes_processed(self) -> Optional[int]:
"""total bytes processed from job statistics, if present."""
return self._total_bytes_processed

@property
def page_size(self) -> Optional[int]:
"""The maximum number of rows in each page of results from this request, if present."""
return self._page_size

def _is_almost_completely_cached(self):
"""Check if all results are completely cached.

Expand Down Expand Up @@ -1924,7 +1929,7 @@ def _should_use_bqstorage(self, bqstorage_client, create_bqstorage_client):
if self._is_almost_completely_cached():
return False

if self.max_results is not None:
if self.max_results is not None or self.page_size is not None:
return False

try:
Expand Down Expand Up @@ -1994,7 +1999,9 @@ def _maybe_warn_max_results(
bqstorage_client:
The BigQuery Storage client intended to use for downloading result rows.
"""
if bqstorage_client is not None and self.max_results is not None:
if bqstorage_client is not None and (
self.max_results is not None or self.page_size is not None
):
warnings.warn(
"Cannot use bqstorage_client if max_results is set, "
"reverting to fetching data with the REST endpoint.",
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_dbapi_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def _mock_rows(
mock_rows,
)
mock_rows.max_results = None
mock_rows.page_size = None
type(mock_rows).job_id = mock.PropertyMock(return_value="test-job-id")
type(mock_rows).location = mock.PropertyMock(return_value="test-location")
type(mock_rows).num_dml_affected_rows = mock.PropertyMock(
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2693,6 +2693,13 @@ def test__should_use_bqstorage_returns_false_if_max_results_set(self):
)
self.assertFalse(result)

def test__should_use_bqstorage_returns_false_if_page_size_set(self):
iterator = self._make_one(page_size=10, first_page_response=None) # not cached
result = iterator._should_use_bqstorage(
bqstorage_client=None, create_bqstorage_client=True
)
self.assertFalse(result)

def test__should_use_bqstorage_returns_false_w_warning_if_missing_dependency(self):
iterator = self._make_one(first_page_response=None) # not cached

Expand Down

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.