Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 400673b

Browse filesBrowse files
fix(bigquery): fix start index with page size for list rows (#27)
Co-authored-by: Peter Lamut <plamut@users.noreply.github.com>
1 parent c88a6dd commit 400673b
Copy full SHA for 400673b

File tree

Expand file treeCollapse file tree

2 files changed

+67
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+67
-0
lines changed
Open diff view settings
Collapse file

‎google/cloud/bigquery/table.py‎

Copy file name to clipboardExpand all lines: google/cloud/bigquery/table.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,8 @@ def _get_next_page_response(self):
13671367
"""
13681368
params = self._get_query_params()
13691369
if self._page_size is not None:
1370+
if self.page_number and "startIndex" in params:
1371+
del params["startIndex"]
13701372
params["maxResults"] = self._page_size
13711373
return self.api_request(
13721374
method=self._HTTP_METHOD, path=self.path, query_params=params
Collapse file

‎tests/unit/test_client.py‎

Copy file name to clipboardExpand all lines: tests/unit/test_client.py
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5612,6 +5612,71 @@ def _bigquery_timestamp_float_repr(ts_float):
56125612
method="GET", path="/%s" % PATH, query_params={}, timeout=7.5
56135613
)
56145614

5615+
def test_list_rows_w_start_index_w_page_size(self):
5616+
from google.cloud.bigquery.schema import SchemaField
5617+
from google.cloud.bigquery.table import Table
5618+
from google.cloud.bigquery.table import Row
5619+
5620+
PATH = "projects/%s/datasets/%s/tables/%s/data" % (
5621+
self.PROJECT,
5622+
self.DS_ID,
5623+
self.TABLE_ID,
5624+
)
5625+
5626+
page_1 = {
5627+
"totalRows": 4,
5628+
"pageToken": "some-page-token",
5629+
"rows": [
5630+
{"f": [{"v": "Phred Phlyntstone"}]},
5631+
{"f": [{"v": "Bharney Rhubble"}]},
5632+
],
5633+
}
5634+
page_2 = {
5635+
"totalRows": 4,
5636+
"rows": [
5637+
{"f": [{"v": "Wylma Phlyntstone"}]},
5638+
{"f": [{"v": "Bhettye Rhubble"}]},
5639+
],
5640+
}
5641+
creds = _make_credentials()
5642+
http = object()
5643+
client = self._make_one(project=self.PROJECT, credentials=creds, _http=http)
5644+
conn = client._connection = make_connection(page_1, page_2)
5645+
full_name = SchemaField("full_name", "STRING", mode="REQUIRED")
5646+
table = Table(self.TABLE_REF, schema=[full_name])
5647+
iterator = client.list_rows(table, max_results=4, page_size=2, start_index=1)
5648+
pages = iterator.pages
5649+
rows = list(six.next(pages))
5650+
extra_params = iterator.extra_params
5651+
f2i = {"full_name": 0}
5652+
self.assertEqual(len(rows), 2)
5653+
self.assertEqual(rows[0], Row(("Phred Phlyntstone",), f2i))
5654+
self.assertEqual(rows[1], Row(("Bharney Rhubble",), f2i))
5655+
5656+
rows = list(six.next(pages))
5657+
5658+
self.assertEqual(len(rows), 2)
5659+
self.assertEqual(rows[0], Row(("Wylma Phlyntstone",), f2i))
5660+
self.assertEqual(rows[1], Row(("Bhettye Rhubble",), f2i))
5661+
self.assertEqual(extra_params, {"startIndex": 1})
5662+
5663+
conn.api_request.assert_has_calls(
5664+
[
5665+
mock.call(
5666+
method="GET",
5667+
path="/%s" % PATH,
5668+
query_params={"startIndex": 1, "maxResults": 2},
5669+
timeout=None,
5670+
),
5671+
mock.call(
5672+
method="GET",
5673+
path="/%s" % PATH,
5674+
query_params={"pageToken": "some-page-token", "maxResults": 2},
5675+
timeout=None,
5676+
),
5677+
]
5678+
)
5679+
56155680
def test_list_rows_empty_table(self):
56165681
response = {"totalRows": "0", "rows": []}
56175682
creds = _make_credentials()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.