forked from googleapis/google-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 1
fix(bigquery): fix start index with page size for list rows #107
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
Draft
HemangChothani
wants to merge
2
commits into
master
Choose a base branch
from
bigquery_start_index_page_size
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5610,6 +5610,73 @@ def _bigquery_timestamp_float_repr(ts_float): | |
| method="GET", path="/%s" % PATH, query_params={}, timeout=7.5 | ||
| ) | ||
|
|
||
| def test_list_rows_w_start_index_w_page_size(self): | ||
| from google.cloud.bigquery.schema import SchemaField | ||
| from google.cloud.bigquery.table import Table | ||
| from google.cloud.bigquery.table import Row | ||
|
|
||
| PATH = "projects/%s/datasets/%s/tables/%s/data" % ( | ||
| self.PROJECT, | ||
| self.DS_ID, | ||
| self.TABLE_ID, | ||
| ) | ||
|
|
||
| page_1 = { | ||
| "totalRows": 4, | ||
| "pageToken": "some-page-token", | ||
| "rows": [ | ||
| {"f": [{"v": "Phred Phlyntstone"}]}, | ||
| {"f": [{"v": "Bharney Rhubble"}]}, | ||
| ], | ||
| } | ||
| page_2 = { | ||
| "totalRows": 4, | ||
| "rows": [ | ||
| {"f": [{"v": "Wylma Phlyntstone"}]}, | ||
| {"f": [{"v": "Bhettye Rhubble"}]}, | ||
| ], | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes this is the response with pages. |
||
| creds = _make_credentials() | ||
| http = object() | ||
| client = self._make_one(project=self.PROJECT, credentials=creds, _http=http) | ||
| conn = client._connection = make_connection(page_1, page_2) | ||
| full_name = SchemaField("full_name", "STRING", mode="REQUIRED") | ||
|
|
||
| table = Table(self.TABLE_REF, schema=[full_name]) | ||
|
|
||
| iterator = client.list_rows(table, max_results=4, page_size=2, start_index=1) | ||
| pages = iterator.pages | ||
| rows = list(six.next(pages)) | ||
| extra_params = iterator.extra_params | ||
| f2i = {"full_name": 0} | ||
| self.assertEqual(len(rows), 2) | ||
| self.assertEqual(rows[0], Row(("Phred Phlyntstone",), f2i)) | ||
| self.assertEqual(rows[1], Row(("Bharney Rhubble",), f2i)) | ||
|
|
||
| rows = list(six.next(pages)) | ||
|
|
||
| self.assertEqual(len(rows), 2) | ||
| self.assertEqual(rows[0], Row(("Wylma Phlyntstone",), f2i)) | ||
| self.assertEqual(rows[1], Row(("Bhettye Rhubble",), f2i)) | ||
| self.assertEqual(extra_params, {"startIndex": 1}) | ||
|
|
||
| conn.api_request.assert_has_calls( | ||
| [ | ||
| mock.call( | ||
| method="GET", | ||
| path="/%s" % PATH, | ||
| query_params={"startIndex": 1, "maxResults": 2}, | ||
| timeout=None, | ||
| ), | ||
| mock.call( | ||
| method="GET", | ||
| path="/%s" % PATH, | ||
| query_params={"pageToken": "some-page-token", "maxResults": 2}, | ||
| timeout=None, | ||
| ), | ||
| ] | ||
| ) | ||
|
|
||
| def test_list_rows_empty_table(self): | ||
| response = {"totalRows": "0", "rows": []} | ||
| creds = _make_credentials() | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, we could write
if self.page_numberinstead ofif self.page_number != 0. Page number is not gonna be negative, so this if-statement will be givingTruein all cases exceptself.page_number == 0. And it's little bit shorter.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I need to delete
startIndexfrom query parameter after first request so when first request hit at that time page_num is 0 and after it increments so except page 0 need to delete for every request.