Skip to content

Commit 79e5fd9

Browse files
committed
fix: fix total rows returned when both start_index and page_size are provided
1 parent 4692747 commit 79e5fd9

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

google/cloud/bigquery/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,7 @@ def _get_query_results(
19751975
location: Optional[str] = None,
19761976
timeout: TimeoutType = DEFAULT_TIMEOUT,
19771977
page_size: int = 0,
1978+
start_index: Optional[int] = None,
19781979
) -> _QueryResults:
19791980
"""Get the query results object for a query job.
19801981
@@ -2002,7 +2003,7 @@ def _get_query_results(
20022003
A new ``_QueryResults`` instance.
20032004
"""
20042005

2005-
extra_params: Dict[str, Any] = {"maxResults": page_size}
2006+
extra_params: Dict[str, Any] = {"maxResults": page_size, "startIndex": start_index}
20062007

20072008
if timeout is not None:
20082009
if not isinstance(timeout, (int, float)):
@@ -2040,6 +2041,7 @@ def _get_query_results(
20402041
query_params=extra_params,
20412042
timeout=timeout,
20422043
)
2044+
breakpoint()
20432045
return _QueryResults.from_api_repr(resource)
20442046

20452047
def job_from_resource(
@@ -4146,6 +4148,7 @@ def _list_rows_from_query_results(
41464148
params["startIndex"] = start_index
41474149

41484150
params["formatOptions.useInt64Timestamp"] = True
4151+
# breakpoint()
41494152
row_iterator = RowIterator(
41504153
client=self,
41514154
api_request=functools.partial(self._call_api, retry, timeout=timeout),

google/cloud/bigquery/job/query.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ def _reload_query_results(
14091409
retry: "retries.Retry" = DEFAULT_RETRY,
14101410
timeout: Optional[float] = None,
14111411
page_size: int = 0,
1412+
start_index: Optional[int] = None,
14121413
):
14131414
"""Refresh the cached query results unless already cached and complete.
14141415
@@ -1468,6 +1469,7 @@ def _reload_query_results(
14681469
location=self.location,
14691470
timeout=transport_timeout,
14701471
page_size=page_size,
1472+
start_index=start_index,
14711473
)
14721474

14731475
def result( # type: ignore # (incompatible with supertype)
@@ -1570,6 +1572,9 @@ def result( # type: ignore # (incompatible with supertype)
15701572
if page_size is not None:
15711573
reload_query_results_kwargs["page_size"] = page_size
15721574

1575+
if start_index is not None:
1576+
reload_query_results_kwargs["start_index"] = start_index
1577+
15731578
try:
15741579
retry_do_query = getattr(self, "_retry_do_query", None)
15751580
if retry_do_query is not None:

google/cloud/bigquery/table.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,12 +1991,14 @@ def _get_next_page_response(self):
19911991
return response
19921992

19931993
params = self._get_query_params()
1994+
import copy
1995+
params_copy = copy.deepcopy(params)
19941996
if self._page_size is not None:
19951997
if self.page_number and "startIndex" in params:
1996-
del params["startIndex"]
1998+
del params_copy["startIndex"]
19971999

19982000
return self.api_request(
1999-
method=self._HTTP_METHOD, path=self.path, query_params=params
2001+
method=self._HTTP_METHOD, path=self.path, query_params=params_copy
20002002
)
20012003

20022004
@property

0 commit comments

Comments
 (0)