Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 685f06a

Browse filesBrowse files
authored
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
1 parent 5980920 commit 685f06a
Copy full SHA for 685f06a

File tree

Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed

‎google/cloud/bigquery/job/query.py

Copy file name to clipboardExpand all lines: google/cloud/bigquery/job/query.py
+2Lines changed: 2 additions & 0 deletions
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

Copy file name to clipboardExpand all lines: tests/unit/job/test_query.py
+14Lines changed: 14 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.