From 685f06a5e7b5df17a53e9eb340ff04ecd1e51d1d Mon Sep 17 00:00:00 2001 From: Steffany Brown <30247553+steffnay@users.noreply.github.com> Date: Wed, 13 Oct 2021 13:17:26 -0700 Subject: [PATCH] feat: allow queryJob.result() to be called on a dryRun (#1015) * feat: allow queryJob.result() to be called on a dryRun * update to return EmptyRowIterator --- google/cloud/bigquery/job/query.py | 2 ++ tests/unit/job/test_query.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/google/cloud/bigquery/job/query.py b/google/cloud/bigquery/job/query.py index 0cb4798be..d9c796cf7 100644 --- a/google/cloud/bigquery/job/query.py +++ b/google/cloud/bigquery/job/query.py @@ -1318,6 +1318,8 @@ def result( If Non-``None`` and non-default ``job_retry`` is provided and the job is not retryable. """ + if self.dry_run: + return _EmptyRowIterator() try: retry_do_query = getattr(self, "_retry_do_query", None) if retry_do_query is not None: diff --git a/tests/unit/job/test_query.py b/tests/unit/job/test_query.py index 4c598d797..8c0b944b0 100644 --- a/tests/unit/job/test_query.py +++ b/tests/unit/job/test_query.py @@ -26,6 +26,7 @@ from google.cloud.bigquery.client import _LIST_ROWS_FROM_QUERY_RESULTS_FIELDS import google.cloud.bigquery.query +from google.cloud.bigquery.table import _EmptyRowIterator from ..helpers import make_connection @@ -989,6 +990,19 @@ def test_result(self): [query_results_call, query_results_call, reload_call, query_page_call] ) + def test_result_dry_run(self): + job_resource = self._make_resource(started=True, location="EU") + job_resource["configuration"]["dryRun"] = True + conn = make_connection() + client = _make_client(self.PROJECT, connection=conn) + job = self._get_target_class().from_api_repr(job_resource, client) + + result = job.result() + + calls = conn.api_request.mock_calls + self.assertIsInstance(result, _EmptyRowIterator) + self.assertEqual(calls, []) + def test_result_with_done_job_calls_get_query_results(self): query_resource_done = { "jobComplete": True,