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: add default_query_job_config property and property setter to BQ client #1511

Merged
merged 3 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ def location(self):
"""Default location for jobs / datasets / tables."""
return self._location

@property
def default_query_job_config(self):
"""Default ``QueryJobConfig``.
Will be merged into job configs passed into the ``query`` method.
"""
return self._default_query_job_config

@default_query_job_config.setter
def default_query_job_config(self, value: QueryJobConfig):
self._default_query_job_config = copy.deepcopy(value)

def close(self):
"""Close the underlying transport objects, releasing system resources.
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,19 @@ def test__get_query_results_hit(self):
self.assertEqual(query_results.total_rows, 10)
self.assertTrue(query_results.complete)

def test_default_query_job_config(self):
from google.cloud.bigquery import QueryJobConfig

creds = _make_credentials()
http = object()
client = self._make_one(project=self.PROJECT, credentials=creds, _http=http)
self.assertIsNone(client.default_query_job_config)

job_config = QueryJobConfig()
job_config.dry_run = True
client.default_query_job_config = job_config
self.assertIsInstance(client.default_query_job_config, QueryJobConfig)

def test_get_service_account_email(self):
path = "/projects/%s/serviceAccount" % (self.PROJECT,)
creds = _make_credentials()
Expand Down