Skip to content

Commit a23092c

Browse files
authored
feat: add default_query_job_config property and property setter to BQ client (#1511)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [x] Make sure to open an issue as a [feature request](https://togithub.com/googleapis/python-bigquery/issues/1512) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) Fixes - [feature request](https://togithub.com/googleapis/python-bigquery/issues/1512)🦕 - [internal bug](https://b.corp.google.com/issues/271044948)
1 parent 75337ee commit a23092c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

google/cloud/bigquery/client.py

+11
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,17 @@ def location(self):
266266
"""Default location for jobs / datasets / tables."""
267267
return self._location
268268

269+
@property
270+
def default_query_job_config(self):
271+
"""Default ``QueryJobConfig``.
272+
Will be merged into job configs passed into the ``query`` method.
273+
"""
274+
return self._default_query_job_config
275+
276+
@default_query_job_config.setter
277+
def default_query_job_config(self, value: QueryJobConfig):
278+
self._default_query_job_config = copy.deepcopy(value)
279+
269280
def close(self):
270281
"""Close the underlying transport objects, releasing system resources.
271282

tests/unit/test_client.py

+13
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,19 @@ def test__get_query_results_hit(self):
413413
self.assertEqual(query_results.total_rows, 10)
414414
self.assertTrue(query_results.complete)
415415

416+
def test_default_query_job_config(self):
417+
from google.cloud.bigquery import QueryJobConfig
418+
419+
creds = _make_credentials()
420+
http = object()
421+
client = self._make_one(project=self.PROJECT, credentials=creds, _http=http)
422+
self.assertIsNone(client.default_query_job_config)
423+
424+
job_config = QueryJobConfig()
425+
job_config.dry_run = True
426+
client.default_query_job_config = job_config
427+
self.assertIsInstance(client.default_query_job_config, QueryJobConfig)
428+
416429
def test_get_service_account_email(self):
417430
path = "/projects/%s/serviceAccount" % (self.PROJECT,)
418431
creds = _make_credentials()

0 commit comments

Comments
 (0)