From 82f2a51cec7cdd6ef1f3958fb2a077a0b624bc67 Mon Sep 17 00:00:00 2001 From: chelsea-lin <124939984+chelsea-lin@users.noreply.github.com> Date: Thu, 2 Mar 2023 07:48:11 -0800 Subject: [PATCH] feat: add default_query_job_config property and property setter to BQ client (#1511) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- google/cloud/bigquery/client.py | 11 +++++++++++ tests/unit/test_client.py | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/google/cloud/bigquery/client.py b/google/cloud/bigquery/client.py index b03266528..af8eaf5a7 100644 --- a/google/cloud/bigquery/client.py +++ b/google/cloud/bigquery/client.py @@ -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. diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index 22f7286db..f38874843 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -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()