Skip to content

Commit 4cd0aa4

Browse files
committed
Add 'QueryJob.results' factory.
Constructs a 'QueryResults' instance, bound to the job. Closes #2083.
1 parent 9307d7e commit 4cd0aa4

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

google/cloud/bigquery/job.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,3 +1073,12 @@ def from_api_repr(cls, resource, client):
10731073
job = cls(name, query, client=client)
10741074
job._set_properties(resource)
10751075
return job
1076+
1077+
def results(self):
1078+
"""Construct a QueryResults instance, bound to this job.
1079+
1080+
:rtype: :class:`~google.cloud.bigquery.query.QueryResults`
1081+
:returns: results instance
1082+
"""
1083+
from google.cloud.bigquery.query import QueryResults
1084+
return QueryResults.from_query_job(self)

unit_tests/bigquery/test_job.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,14 @@ def test_from_api_repr_w_properties(self):
13861386
self.assertTrue(dataset._client is client)
13871387
self._verifyResourceProperties(dataset, RESOURCE)
13881388

1389+
def test_results(self):
1390+
from google.cloud.bigquery.query import QueryResults
1391+
client = _Client(self.PROJECT)
1392+
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1393+
results = job.results()
1394+
self.assertIsInstance(results, QueryResults)
1395+
self.assertTrue(results._job is job)
1396+
13891397
def test_begin_w_bound_client(self):
13901398
PATH = 'projects/%s/jobs' % self.PROJECT
13911399
RESOURCE = self._makeResource()

0 commit comments

Comments
 (0)