Skip to content

Commit 0742cf2

Browse files
steffnayabdelmegahedgoogle
authored andcommitted
feat: allow queryJob.result() to be called on a dryRun (googleapis#1015)
* feat: allow queryJob.result() to be called on a dryRun * update to return EmptyRowIterator
1 parent 726eb24 commit 0742cf2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

google/cloud/bigquery/job/query.py

+2
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,8 @@ def result(
13181318
If Non-``None`` and non-default ``job_retry`` is
13191319
provided and the job is not retryable.
13201320
"""
1321+
if self.dry_run:
1322+
return _EmptyRowIterator()
13211323
try:
13221324
retry_do_query = getattr(self, "_retry_do_query", None)
13231325
if retry_do_query is not None:

tests/unit/job/test_query.py

+14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
from google.cloud.bigquery.client import _LIST_ROWS_FROM_QUERY_RESULTS_FIELDS
2828
import google.cloud.bigquery.query
29+
from google.cloud.bigquery.table import _EmptyRowIterator
2930

3031
from ..helpers import make_connection
3132

@@ -989,6 +990,19 @@ def test_result(self):
989990
[query_results_call, query_results_call, reload_call, query_page_call]
990991
)
991992

993+
def test_result_dry_run(self):
994+
job_resource = self._make_resource(started=True, location="EU")
995+
job_resource["configuration"]["dryRun"] = True
996+
conn = make_connection()
997+
client = _make_client(self.PROJECT, connection=conn)
998+
job = self._get_target_class().from_api_repr(job_resource, client)
999+
1000+
result = job.result()
1001+
1002+
calls = conn.api_request.mock_calls
1003+
self.assertIsInstance(result, _EmptyRowIterator)
1004+
self.assertEqual(calls, [])
1005+
9921006
def test_result_with_done_job_calls_get_query_results(self):
9931007
query_resource_done = {
9941008
"jobComplete": True,

0 commit comments

Comments
 (0)