Skip to content

Commit

Permalink
feat: add default_query_job_config property and property setter to BQ…
Browse files Browse the repository at this point in the history
… 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)
  • Loading branch information
chelsea-lin committed Mar 2, 2023
1 parent 75337ee commit a23092c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit a23092c

Please sign in to comment.