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 1 commit
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
4 changes: 3 additions & 1 deletion google/cloud/bigquery/job/query.py
Expand Up @@ -1262,7 +1262,7 @@ def result(
timeout: float = None,
start_index: int = None,
job_retry: "retries.Retry" = DEFAULT_JOB_RETRY,
) -> Union["RowIterator", _EmptyRowIterator]:
) -> Union["RowIterator", _EmptyRowIterator, None]:
"""Start the job and wait for it to complete and get the result.

Args:
Expand Down 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
steffnay marked this conversation as resolved.
Show resolved Hide resolved
try:
retry_do_query = getattr(self, "_retry_do_query", None)
if retry_do_query is not None:
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/job/test_query.py
Expand Up @@ -989,6 +989,40 @@ def test_result(self):
[query_results_call, query_results_call, reload_call, query_page_call]
)

def test_result_dry_run(self):
query_resource_done = {
steffnay marked this conversation as resolved.
Show resolved Hide resolved
"jobComplete": True,
"jobReference": {
"projectId": self.PROJECT,
"jobId": self.JOB_ID,
steffnay marked this conversation as resolved.
Show resolved Hide resolved
"location": "EU",
},
"schema": {"fields": [{"name": "col1", "type": "STRING"}]},
"totalRows": "2",
}
job_resource = self._make_resource(started=True, location="EU")
job_resource["configuration"]["dryRun"] = True
# job_resource_done = self._make_resource(started=True, ended=True, location="EU")
# job_resource_done["configuration"]["query"]["destinationTable"] = {
# "projectId": "dest-project",
# "datasetId": "dest_dataset",
# "tableId": "dest_table",
# }
results_page_resource = {
"totalRows": "1",
"pageToken": None,
"rows": [{"f": [{"v": "abc"}]}],
}
conn = make_connection(query_resource_done, results_page_resource)
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.assertEqual(result, None)
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