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 — perf: use `jobs.getQueryResults` to download result sets by tswast · Pull Request #347 · googleapis/python-bigquery

This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Conversation

@tswast

@tswast tswast commented Oct 27, 2020 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Since getQueryResults was already used to wait for the job to finish,
this avoids an additional call to tabledata.list. The first page of
results are cached in-memory.

Additional changes will come in the future to avoid calling the BQ
Storage API when the cached results contain the full result set.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Towards #362

Sorry, something went wrong.

Uh oh!

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

All reactions
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 27, 2020
@tswast

tswast commented Oct 27, 2020

Copy link
Copy Markdown
Contributor Author

Based on #341

All reactions

Sorry, something went wrong.

Uh oh!

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

tswast
tswast commented Oct 28, 2020
View reviewed changes
Comment thread google/cloud/bigquery/job.py Outdated
)

self._query_results = None
self._get_query_results_kwargs = {}

@tswast tswast Oct 28, 2020

Copy link
Copy Markdown
Contributor Author

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.

Does this need to be a thread-local variable?

Sorry, something went wrong.

Uh oh!

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

All reactions

@tswast tswast Oct 28, 2020

Copy link
Copy Markdown
Contributor Author

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.

Actually, the cached query results might need to be thread-local too. Imagine if two threads called result with different starting indexes and/or max results.

Sorry, something went wrong.

Uh oh!

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

All reactions

@tswast tswast Oct 28, 2020

Copy link
Copy Markdown
Contributor Author

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.

We'll also need some logic like

https://github.com/googleapis/google-cloud-go/blob/925033712191bce44fa99eb117d6531106042272/bigquery/iterator.go#L314

to see if we can use the cached page if result is called more than once

Sorry, something went wrong.

Uh oh!

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

All reactions

@tswast tswast Oct 30, 2020

Copy link
Copy Markdown
Contributor Author

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.

Done in latest commit.

Sorry, something went wrong.

Uh oh!

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

All reactions
@tswast
perf: use jobs.getQueryResults to download result sets
983c8d2
Since `getQueryResults` was already used to wait for the job to finish,
this avoids an additional call to `tabledata.list`. The first page of
results are cached in-memory.

Additional changes will come in the future to avoid calling the BQ
Storage API when the cached results contain the full result set.
@tswast
tswast force-pushed the optimized-query-getQueryResults branch from 7364196 to 983c8d2 Compare October 29, 2020 19:15
@tswast
fix: validate the query results cache before using
f52ed71
Also, move to thread-local variables for values that were
intended to track parameters across methods.
@tswast
tswast marked this pull request as ready for review October 30, 2020 21:40
@tswast
tswast requested review from a team and shollyman October 30, 2020 21:40
tswast added 4 commits November 2, 2020 09:44
@tswast
Merge remote-tracking branch 'upstream/master' into optimized-query-g…
e149360
…etQueryResults
@tswast
blacken. update dbapi to use thread local var
9b5920f
@tswast
fix dbapi tests
07e6043
@tswast
fix system test
af2e2cc
startIndex is no longer passed to the iterator
It is used in the initial (cached) call to
getQueryResults
@tswast tswast mentioned this pull request Nov 2, 2020
refactor: split job.py and test_job.py #358
Closed
tswast added 2 commits November 2, 2020 10:50
@tswast
add unit tests for missing coverage
540d530
@tswast
blacken
6e83fbf
tswast
tswast commented Nov 2, 2020
View reviewed changes
Comment thread google/cloud/bigquery/client.py
Iterator of row data
:class:`~google.cloud.bigquery.table.Row`-s.
"""
row_iterator = RowIterator(

@tswast tswast Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

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.

Be sure to populate extra args with the field projection. We only need rows and page token.

Sorry, something went wrong.

Uh oh!

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

All reactions
@tswast tswast added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Nov 2, 2020
@tswast

tswast commented Nov 3, 2020 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Per our discussion, I'll be splitting this into 2 PRs:

  1. Call getQueryResults (no cache) from RowIterator -- make sure to add a projection to exclude the schema and other irrelevant job stats. perf: use jobs.getQueryResults to download result sets #363
  2. Cache the first page of results.

I'll base them on the refactoring to split up the giant job module here: #361

All reactions

Sorry, something went wrong.

Uh oh!

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

@tswast tswast closed this Nov 4, 2020
@tswast tswast mentioned this pull request Nov 5, 2020
perf: cache first page of jobs.getQueryResults rows #374
Merged
4 tasks done
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@shollyman shollyman Awaiting requested review from shollyman

Uh oh!

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

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement. do not merge Indicates a pull request not ready for merge, due to either quality or timing.

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.

1 participant

@tswast
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.