Skip to content

Commit

Permalink
remove unnecessary if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
tswast committed Apr 13, 2024
1 parent fddb557 commit 6a43cfd
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions google/cloud/bigquery/job/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ def _begin(self, client=None, retry=DEFAULT_RETRY, timeout=None):
def _reload_query_results(
self, retry: "retries.Retry" = DEFAULT_RETRY, timeout: Optional[float] = None
):
"""Refresh the cached query results.
"""Refresh the cached query results unless already cached and complete.
Args:
retry (Optional[google.api_core.retry.Retry]):
Expand All @@ -1392,6 +1392,8 @@ def _reload_query_results(
The number of seconds to wait for the underlying HTTP transport
before using ``retry``.
"""
# Optimization: avoid a call to jobs.getQueryResults if it's already
# been fetched, e.g. from jobs.query first page of results.
if self._query_results and self._query_results.complete:
return

Expand Down Expand Up @@ -1556,14 +1558,16 @@ def is_job_done():
restart_query_job = True
raise self.exception()
else:
# Optimization: avoid a call to jobs.getQueryResults if
# it's already been fetched, e.g. from jobs.query first
# page of results.
if (
self._query_results is None
or not self._query_results.complete
):
self._reload_query_results(retry=retry, timeout=timeout)
# Make sure that the _query_results are cached so we
# can return a complete RowIterator.
#
# Note: As an optimization, _reload_query_results
# doesn't make any API calls if the query results are
# already cached and have jobComplete=True in the
# response from the REST API. This ensures we aren't
# making any extra API calls if the previous loop
# iteration fetched the finished job.
self._reload_query_results(retry=retry, timeout=timeout)
return True

# Call jobs.getQueryResults with max results set to 0 just to
Expand Down

0 comments on commit 6a43cfd

Please sign in to comment.