Browse files

Remove QueryJob.results() (#3661)

  • Loading branch information...
theacodes committed Jul 24, 2017
1 parent 506a304 commit 40a3b4929f3fe9b6568b271900979ca486c083a6
@@ -15,34 +15,13 @@
import collections
import datetime
import numbers
import time
import six
from import bigquery
from import exceptions
def wait_for_job(job):
"""Waits for a job to complete by polling until the state is `DONE`.
Sleeps 1 second between calls to the BigQuery API.
:type job: :class:``
:param job: Wait for this job to finish.
:raises: :class:``
if the job fails.
while True:
if job.state == 'DONE':
if job.error_result:
raise exceptions.DatabaseError(job.errors)
def scalar_to_query_parameter(value, name=None):
"""Convert a scalar value into a query parameter.
@@ -21,7 +21,7 @@
from import _helpers
from import exceptions
# Per PEP 249: A 7-item sequence containing information describing one result
# column. The first two items (name and type_code) are mandatory, the other
@@ -148,9 +148,11 @@ def execute(self, operation, parameters=None):
query_job.use_legacy_sql = False
query_results = query_job.results()
query_results = query_job.result()
raise exceptions.DatabaseError(query_job.errors)
# Force the iterator to run because the query_results doesn't
# have the total_rows populated. See:
@@ -16,7 +16,6 @@
import collections
import threading
import warnings
import six
from six.moves import http_client
@@ -1264,21 +1263,6 @@ def query_results(self):
from import QueryResults
return QueryResults.from_query_job(self)
def results(self):
This method is deprecated. Use :meth:`query_results` or :meth:`result`.
Construct a QueryResults instance, bound to this job.
:rtype: :class:``
:returns: The query results.
'QueryJob.results() is deprecated. Please use query_results() or '
'result().', DeprecationWarning)
return self.query_results()
def result(self, timeout=None):
"""Start the job and wait for it to complete and get the result.
@@ -16,48 +16,11 @@
import math
import unittest
import mock
from import _helpers
from import exceptions
class Test_wait_for_job(unittest.TestCase):
def _mock_job(self):
from import job
mock_job = mock.create_autospec(job.QueryJob)
mock_job.state = 'RUNNING'
mock_job._mocked_iterations = 0
def mock_reload():
mock_job._mocked_iterations += 1
if mock_job._mocked_iterations >= 2:
mock_job.state = 'DONE'
mock_job.reload.side_effect = mock_reload
return mock_job
def _call_fut(self, job):
from import wait_for_job
with mock.patch('time.sleep'):
def test_wo_error(self):
mock_job = self._mock_job()
mock_job.error_result = None
self.assertEqual('DONE', mock_job.state)
def test_w_error(self):
from import exceptions
mock_job = self._mock_job()
mock_job.error_result = {'reason': 'invalidQuery'}
self.assertRaises(exceptions.DatabaseError, self._call_fut, mock_job)
self.assertEqual('DONE', mock_job.state)
class TestQueryParameters(unittest.TestCase):
def test_scalar_to_query_parameter(self):
@@ -42,7 +42,7 @@ def _mock_job(
mock_job = mock.create_autospec(job.QueryJob)
mock_job.error_result = None
mock_job.state = 'DONE'
mock_job.results.return_value = self._mock_results(
mock_job.result.return_value = self._mock_results(
rows=rows, schema=schema,
return mock_job
@@ -219,6 +219,24 @@ def test_execute_w_query(self):
row = cursor.fetchone()
def test_execute_raises_if_result_raises(self):
from import client
from import job
from import connect
from import exceptions
job = mock.create_autospec(job.QueryJob)
job.result.side_effect ='')
client = mock.create_autospec(client.Client)
client.run_async_query.return_value = job
connection = connect(client)
cursor = connection.cursor()
with self.assertRaises(exceptions.DatabaseError):
cursor.execute('SELECT 1')
def test_executemany_w_dml(self):
from import connect
connection = connect(
@@ -13,7 +13,6 @@
# limitations under the License.
import copy
import warnings
from six.moves import http_client
import unittest
@@ -1560,16 +1559,6 @@ def test_query_results(self):
self.assertIsInstance(results, QueryResults)
self.assertIs(results._job, job)
def test_results_is_deprecated(self):
client = _Client(self.PROJECT)
job = self._make_one(self.JOB_NAME, self.QUERY, client)
with warnings.catch_warnings(record=True) as warned:
self.assertEqual(len(warned), 1)
self.assertIn('deprecated', str(warned[0]))
def test_result(self):
from import QueryResults

0 comments on commit 40a3b49

Please sign in to comment.