Skip to content

Commit

Permalink
feat: allow queryJob.result() to be called on a dryRun (#1015)
Browse files Browse the repository at this point in the history
* feat: allow queryJob.result() to be called on a dryRun

* update to return EmptyRowIterator
  • Loading branch information
steffnay committed Oct 13, 2021
1 parent 5980920 commit 685f06a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions google/cloud/bigquery/job/query.py
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/job/test_query.py
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 685f06a

Please sign in to comment.