Skip to content

Commit e89a707

Browse files
authored
fix: table iterator should not use bqstorage when page_size is not None (googleapis#2154)
* fix: table iterator should not use bqstorage when page_size is not None * fix dbapi cursor tests
1 parent c2343dd commit e89a707

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

google/cloud/bigquery/table.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,11 @@ def total_bytes_processed(self) -> Optional[int]:
18731873
"""total bytes processed from job statistics, if present."""
18741874
return self._total_bytes_processed
18751875

1876+
@property
1877+
def page_size(self) -> Optional[int]:
1878+
"""The maximum number of rows in each page of results from this request, if present."""
1879+
return self._page_size
1880+
18761881
def _is_almost_completely_cached(self):
18771882
"""Check if all results are completely cached.
18781883
@@ -1924,7 +1929,7 @@ def _should_use_bqstorage(self, bqstorage_client, create_bqstorage_client):
19241929
if self._is_almost_completely_cached():
19251930
return False
19261931

1927-
if self.max_results is not None:
1932+
if self.max_results is not None or self.page_size is not None:
19281933
return False
19291934

19301935
try:
@@ -1994,7 +1999,9 @@ def _maybe_warn_max_results(
19941999
bqstorage_client:
19952000
The BigQuery Storage client intended to use for downloading result rows.
19962001
"""
1997-
if bqstorage_client is not None and self.max_results is not None:
2002+
if bqstorage_client is not None and (
2003+
self.max_results is not None or self.page_size is not None
2004+
):
19982005
warnings.warn(
19992006
"Cannot use bqstorage_client if max_results is set, "
20002007
"reverting to fetching data with the REST endpoint.",

tests/unit/test_dbapi_cursor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def _mock_rows(
161161
mock_rows,
162162
)
163163
mock_rows.max_results = None
164+
mock_rows.page_size = None
164165
type(mock_rows).job_id = mock.PropertyMock(return_value="test-job-id")
165166
type(mock_rows).location = mock.PropertyMock(return_value="test-location")
166167
type(mock_rows).num_dml_affected_rows = mock.PropertyMock(

tests/unit/test_table.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,13 @@ def test__should_use_bqstorage_returns_false_if_max_results_set(self):
26932693
)
26942694
self.assertFalse(result)
26952695

2696+
def test__should_use_bqstorage_returns_false_if_page_size_set(self):
2697+
iterator = self._make_one(page_size=10, first_page_response=None) # not cached
2698+
result = iterator._should_use_bqstorage(
2699+
bqstorage_client=None, create_bqstorage_client=True
2700+
)
2701+
self.assertFalse(result)
2702+
26962703
def test__should_use_bqstorage_returns_false_w_warning_if_missing_dependency(self):
26972704
iterator = self._make_one(first_page_response=None) # not cached
26982705

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy