GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Move BigQuery list_ methods to use iterators by dhermes · Pull Request #2565 · googleapis/google-cloud-python

Conversation

@dhermes

@dhermes dhermes commented Oct 19, 2016

Copy link
Copy Markdown
Contributor

Follow up to #2561. This only covers Dataset.list_tables() and Table.fetch_data(). It may also be "correct" to use an Iterator in

  • QueryResults.fetch_data
  • QueryResults.run (via QueryResults._build_resource)

but I wanted to get eyes on this change first / opinion from the original author (@tseaver) before moving forward.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@dhermes dhermes added the api: bigquery Issues related to the BigQuery API. label Oct 19, 2016
@dhermes dhermes assigned daspecster and tseaver Oct 19, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 19, 2016
daspecster
daspecster reviewed Oct 19, 2016
View reviewed changes
Comment thread scripts/run_pylint.py
TEST_RC_REPLACEMENTS = {
'FORMAT': {
'max-module-lines': 1960,
'max-module-lines': 2000,

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/table.py
page_token=page_token, max_results=max_results,
page_start=_rows_page_start)
iterator.schema = self._schema
# Over-ride the key used to retrieve the next page token.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/_helpers.py Outdated


def _row_from_json(row, schema):
"""Convert JSON row data to row w/ appropriate types.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/_helpers.py Outdated
"""Convert JSON row data to row w/ appropriate types.

:type row: dict
:param row:

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/google/cloud/bigquery/table.py
return _row_from_json(resource, iterator.schema)


# pylint: disable=unused-argument

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/unit_tests/test_table.py
max_results=MAX,
page_token=TOKEN)
iterator = table.fetch_data(
client=client2, max_results=MAX, page_token=TOKEN)

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Oct 19, 2016

Copy link
Copy Markdown
Contributor Author

@tseaver Can you weigh in here? I'm especially curious how you feel about fetch_data (both in Table and QueryResults) and QueryResults.run.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Oct 20, 2016

Copy link
Copy Markdown
Contributor

I'm especially curious how you feel about fetch_data (both in Table and QueryResults) and QueryResults.run.

+0 for adding it to fetch_data: those methods currently return a 3-tuple, row_data, total_rows, page_token, which means we would have to choose what to do with the total_rows count.

-1 for adding it to run: that doesn't return row data, paged or not.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Oct 20, 2016

Copy link
Copy Markdown
Contributor Author

+0 for adding it to fetch_data: those methods currently return a 3-tuple, row_data, total_rows, page_token, which means we would have to choose what to do with the total_rows count.

Check out the implementation, I put total_rows on iterator.page.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver
tseaver reviewed Oct 20, 2016
View reviewed changes
Comment thread bigquery/google/cloud/bigquery/table.py Outdated
"""
total_rows = response.get('totalRows')
if total_rows is not None:
page.total_rows = int(total_rows)

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Oct 20, 2016

Copy link
Copy Markdown
Contributor

LGTM, once you decide about my question about where total_rows should be exposed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Oct 20, 2016

Copy link
Copy Markdown
Contributor Author

@tseaver I'll put total_rows on both once back at keyboard. Now that you've seen the implementation, does it seem appropriate to change QueryResults.fetch_data over as well?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Oct 20, 2016

Copy link
Copy Markdown
Contributor Author

@tseaver I started writing the code to put total_rows on the Iterator instance and realized something. If while paging, the first request has totalRows: 1200 and the second request somehow has the key missing, then on the second page we'd either have to del iterator.total_rows or iterator.total_rows = None or have an invalid value.

Given this scenario, it seems like my_iter.page.total_rows is the only real correct place for total_rows since it is actually a page-specific value (it may even change between pages if the backend is processing more rows between requests?)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Oct 20, 2016

Copy link
Copy Markdown
Contributor

@dhermes For queries, the docs say totalRows is only present on a page of results if the query has already completed: we can therefore presume that i will not change.

For tables, the docs say only that totalRows represents "[t]he total number of rows in the complete table." We would have to ask the back-end team whether the page_token encodes a "timestamped" cursor which would make totalRows constant across pages, even if new values were inserted into the table in the meanwhile.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Oct 25, 2016

Copy link
Copy Markdown
Contributor

@fhoffa Can you chime in on how stable the totalRows value is for tabledata?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver tseaver added the backend label Oct 25, 2016
dhermes added 4 commits October 31, 2016 22:30
@dhermes
Making BigQuery dataset.list_tables() into an iterator.
5b0f9c8
@dhermes
Refactoring _rows_from_json BigQuery helper.
092dd09
In particular, isolating the logic useful to work on a single row.
@dhermes
Making BigQuery table.fetch_data() into an iterator.
0e7b01f
@dhermes
Rebase fixes.
d3a6dff
@dhermes
dhermes force-pushed the bigquery-iterators-2 branch from e439de8 to d3a6dff Compare November 1, 2016 05:53
@dhermes
Review feedback: moving total_rows from Page to Iterator.
76fa05c
Also fixing BigQuery system test in the process.
@dhermes

dhermes commented Nov 1, 2016

Copy link
Copy Markdown
Contributor Author

@tseaver I put total_rows only on the Iterator and just allowed it to be None if missing in the response.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver
tseaver approved these changes Nov 1, 2016
View reviewed changes
@dhermes
dhermes merged commit 4b4023f into googleapis:master Nov 1, 2016
@dhermes
dhermes deleted the bigquery-iterators-2 branch November 1, 2016 15:55
@dhermes dhermes mentioned this pull request Nov 14, 2016
Upgrading core to version to 0.21.0. #2733
Merged
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
@dhermes
Merge pull request googleapis#2565 from dhermes/bigquery-iterators-2
9d10874
Move BigQuery list_ methods to use iterators
@theacodes theacodes unassigned daspecster Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

2 more reviewers
@daspecster daspecster daspecster left review comments
@tseaver tseaver tseaver approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@tseaver tseaver

Labels

api: bigquery Issues related to the BigQuery API. backend cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@dhermes @tseaver @daspecster @googlebot
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.