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 — feat: add progress bar for to_arrow method by HemangChothani · Pull Request #352 · googleapis/python-bigquery

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

Conversation

@HemangChothani

@HemangChothani HemangChothani commented Oct 29, 2020

Copy link
Copy Markdown
Contributor

Fixes #343

  • PR open for the feedback and suggestions.

  • Currently implemented for 'QueryJob.to_arrow' method

  • When the cacheHit for result is true at time query_plan is blank so can't implement progress bar.

Sorry, something went wrong.

Uh oh!

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

All reactions
@HemangChothani
feat: add progress bar for to_arrow method
05f101e
@HemangChothani
HemangChothani requested a review from tswast October 29, 2020 13:17
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 29, 2020
tswast
tswast reviewed Oct 29, 2020
View reviewed changes
Comment thread google/cloud/bigquery/job.py Outdated
import copy
import re
import threading
import tqdm

@tswast tswast Oct 29, 2020

Copy link
Copy Markdown
Contributor

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.

This needs to be an optional import. See:

python-bigquery/google/cloud/bigquery/table.py

Lines 39 to 42 in 20f473b

try:
import tqdm
except ImportError: # pragma: NO COVER
tqdm = None

Sorry, something went wrong.

Uh oh!

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

All reactions
tswast
tswast reviewed Oct 29, 2020
View reviewed changes
Comment thread google/cloud/bigquery/job.py Outdated
rows._preserve_order = _contains_order_by(self.query)
return rows

def _get_progress_bar(self, progress_bar_type, description, total, unit):

@tswast tswast Oct 29, 2020

Copy link
Copy Markdown
Contributor

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.

Seems like this is very close to the logic in table.py

python-bigquery/google/cloud/bigquery/table.py

Line 1374 in 20f473b

def _get_progress_bar(self, progress_bar_type):

I'd suggest creating a _tqdm_helpers.py module similar to our pandas helpers to hold this logic for both Table and Job logic.

Sorry, something went wrong.

Uh oh!

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

All reactions
@HemangChothani
feat: add progress bar for to_dataframe
288739f
@HemangChothani
HemangChothani marked this pull request as ready for review November 2, 2020 07:51
@HemangChothani
HemangChothani requested a review from a team November 2, 2020 07:51
@HemangChothani
Merge branch 'master' of https://github.com/googleapis/python-bigquery …
d94894c
…into bigquery_issue_343
tswast
tswast suggested changes Nov 3, 2020
View reviewed changes
Comment thread google/cloud/bigquery/job.py Outdated
..versionadded:: 1.17.0
"""
return self.result().to_arrow(
if self.query_plan and progress_bar_type:

@tswast tswast Nov 3, 2020

Copy link
Copy Markdown
Contributor

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.

Is this logic necessary if we are calling to_arrow? Can't we rely on to_arrow's progress bar support?

Sorry, something went wrong.

Uh oh!

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

All reactions

@HemangChothani HemangChothani Nov 4, 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.

Sorry, didn't get this point, are you talking about table.to_arrow() progress bar support?

Sorry, something went wrong.

Uh oh!

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

All reactions

@tswast tswast Nov 5, 2020

Copy link
Copy Markdown
Contributor

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.

Oh, I was getting this confused with RowIterator, where to_dataframe relies on to_arrow's progress bar support. I do wonder if some of this "waiting for the query to finish" logic could be refactored into a _tqdm_helpers.py function, since it should be identical between to_dataframe and to_arrow

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread google/cloud/bigquery/job.py Outdated
"""
return self.result().to_dataframe(
query_plan = self.query_plan
if query_plan and progress_bar_type:

@tswast tswast Nov 3, 2020

Copy link
Copy Markdown
Contributor

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.

query_plan can get updated as the job progresses. I'd prefer if this always created a progress bar, but had a generic message when the job is still pending and there isn't a query plan.

Sorry, something went wrong.

Uh oh!

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

All reactions
HemangChothani added 2 commits November 4, 2020 19:13
@HemangChothani
feat: add default progress bar and unit test
fa1bb49
@HemangChothani
Merge branch 'master' of https://github.com/googleapis/python-bigquery …
485bcf5
…into bigquery_issue_343
tswast
tswast reviewed Nov 5, 2020
View reviewed changes
Comment thread google/cloud/bigquery/job.py Outdated
)

try:
query_result = self.result(timeout=0.5)

@tswast tswast Nov 5, 2020

Copy link
Copy Markdown
Contributor

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 should make constants for this (PROGRESS_BAR_UPDATE_INTERVAL, for example)

Sorry, something went wrong.

Uh oh!

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

All reactions
@HemangChothani
feat: resolve conflict and move code to _tqdm_helper file
f9b2ff7
tswast
tswast reviewed Nov 10, 2020
View reviewed changes

@tswast tswast left a comment

Copy link
Copy Markdown
Contributor

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.

Looking good. A few nits regarding naming and indentation.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread google/cloud/bigquery/_tqdm_helpers.py Outdated
return None


def _query_job_result_helper(query_job, progress_bar_type=None):

@tswast tswast Nov 10, 2020

Copy link
Copy Markdown
Contributor

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.

Let's use active verbs in this helper name.

Suggested change
def _query_job_result_helper(query_job, progress_bar_type=None):
def wait_for_query(query_job, progress_bar_type=None):

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread google/cloud/bigquery/_tqdm_helpers.py Outdated

def _query_job_result_helper(query_job, progress_bar_type=None):
"""Return query result and display a progress bar while the query running, if tqdm is installed."""
if progress_bar_type:

@tswast tswast Nov 10, 2020

Copy link
Copy Markdown
Contributor

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 can reduce the level of indentation if we exit early. Also, I think we'll want to pass through some keyword arguments to result(), correct?

Suggested change
if progress_bar_type:
if progress_bar_type is None:
return query_job.result()

Aside (not relevant for this PR): we'll eventually want to pass additional arguments to result() whenever we implement #296

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread google/cloud/bigquery/_tqdm_helpers.py Outdated
_PROGRESS_BAR_UPDATE_INTERVAL = 0.5


def _get_progress_bar(progress_bar_type, description, total, unit):

@tswast tswast Nov 10, 2020

Copy link
Copy Markdown
Contributor

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 want to use these helpers from other modules, let's remove the (redundant because of private module) leading _.

Suggested change
def _get_progress_bar(progress_bar_type, description, total, unit):
def get_progress_bar(progress_bar_type, description, total, unit):

Sorry, something went wrong.

Uh oh!

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

All reactions
tswast
tswast reviewed Nov 10, 2020
View reviewed changes
Comment thread google/cloud/bigquery/_tqdm_helpers.py Outdated
progress_bar = _get_progress_bar(
progress_bar_type, "Query is running", 1, "query"
)
if query_job.query_plan:

@tswast tswast Nov 10, 2020

Copy link
Copy Markdown
Contributor

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.

This should be one level deeper. I'd like to see the while True loop, even when query_plan is not initially populated.

Sorry, something went wrong.

Uh oh!

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

All reactions
HemangChothani added 2 commits November 12, 2020 17:23
@HemangChothani
feat: nit
481fa05
@HemangChothani
Merge branch 'master' of https://github.com/googleapis/python-bigquery …
c1ee80e
…into bigquery_issue_343
tswast
tswast suggested changes Nov 12, 2020
View reviewed changes

@tswast tswast left a comment

Copy link
Copy Markdown
Contributor

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'd expect the while loop to contain the following steps:

  1. Call result() with a short-ish timeout.
  2. Call reload()
  3. Update the progress bar (different cases for query_plan present or not)

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread google/cloud/bigquery/_tqdm_helpers.py Outdated
"""Return query result and display a progress bar while the query running, if tqdm is installed."""
if progress_bar_type is None:
query_result = query_job.result()
else:

@tswast tswast Nov 12, 2020

Copy link
Copy Markdown
Contributor

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 meant that you could return query_job.result() here. The else statement is then unnecessary, saving us 1 level of indentation.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread google/cloud/bigquery/_tqdm_helpers.py Outdated
i += 1
continue
else:
query_result = query_job.result()

@tswast tswast Nov 12, 2020

Copy link
Copy Markdown
Contributor

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 need a timeout here. It's not clear to me why the above try block is even in the if statement.

Sorry, something went wrong.

Uh oh!

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

All reactions

@tswast tswast Nov 12, 2020

Copy link
Copy Markdown
Contributor

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.

Looks like the only difference is the presence of total, which could be set to a default value in the case where query_plan is not present.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread google/cloud/bigquery/_tqdm_helpers.py Outdated
while True:
if query_job.query_plan:
total = len(query_job.query_plan)
query_job.reload() # Refreshes the state via a GET request.

@tswast tswast Nov 12, 2020

Copy link
Copy Markdown
Contributor

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.

Wouldn't we only want to call reload after result times out?

Also, why would we only call reload inside this if statement? The job might not have a query_plan until after reload is called in many cases.

Sorry, something went wrong.

Uh oh!

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

All reactions
HemangChothani added 2 commits November 13, 2020 13:28
@HemangChothani
feat: result timout for without queryplan
47d393c
@HemangChothani
Merge branch 'master' of https://github.com/googleapis/python-bigquery …
e1d017c
…into bigquery_issue_343
@HemangChothani

HemangChothani commented Nov 13, 2020

Copy link
Copy Markdown
Contributor Author

system test failed not related to changes.

All reactions

Sorry, something went wrong.

Uh oh!

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

tswast
tswast approved these changes Nov 16, 2020
View reviewed changes

@tswast tswast left a comment

Copy link
Copy Markdown
Contributor

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.

Love it!

P.S. I have opened #388 to fix those failing tests.

Sorry, something went wrong.

Uh oh!

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

All reactions
@tswast
tswast merged commit dc78edd into googleapis:master Nov 16, 2020
@tswast tswast mentioned this pull request Nov 16, 2020
Implement initial "waiting" logs with tqdm? googleapis/python-bigquery-pandas#327
Closed
@willbowditch willbowditch mentioned this pull request Nov 25, 2020
Wait for Query hangs indefinitely for some queries #403
Closed
@release-please release-please Bot mentioned this pull request Jan 4, 2022
chore(main): release python-bigquery 1.27.1 #1097
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

1 more reviewer
@tswast tswast tswast approved these changes
Reviewers whose approvals may not affect merge requirements

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.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

feat: progress bar during query in QueryJob.to_dataframe and QueryJob.to_arrow

Uh oh!

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

2 participants

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