Skip to content

Commit

Permalink
Merge pull request #1675 from tseaver/1673-bigquery-reify_query_job
Browse files Browse the repository at this point in the history
Cache job constructed for a synchronous query.
  • Loading branch information
tseaver committed Mar 29, 2016
2 parents 7aafecd + b53fec5 commit b8eac84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions gcloud/bigquery/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, query, client):
self._properties = {}
self.query = query
self._configuration = _SyncQueryConfiguration()
self._job = None

@property
def project(self):
Expand Down Expand Up @@ -134,9 +135,12 @@ def job(self):
:returns: Job instance used to run the query (None until
``jobReference`` property is set by the server).
"""
job_ref = self._properties.get('jobReference')
if job_ref is not None:
return QueryJob(job_ref['jobId'], self.query, self._client)
if self._job is None:
job_ref = self._properties.get('jobReference')
if job_ref is not None:
self._job = QueryJob(job_ref['jobId'], self.query,
self._client)
return self._job

@property
def page_token(self):
Expand Down
2 changes: 2 additions & 0 deletions gcloud/bigquery/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def test_job_w_jobid(self):
self.assertEqual(job.query, self.QUERY)
self.assertTrue(job._client is client)
self.assertEqual(job.name, SERVER_GENERATED)
fetched_later = query.job
self.assertTrue(fetched_later is job)

def test_schema(self):
client = _Client(self.PROJECT)
Expand Down

0 comments on commit b8eac84

Please sign in to comment.