Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow queryJob.result() to be called on a dryRun #1015

Merged
merged 3 commits into from Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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, [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks for checking that there were no API requests.


def test_result_with_done_job_calls_get_query_results(self):
query_resource_done = {
"jobComplete": True,
Expand Down