From dd078249caed84ed7aa1c488bf6729340498cfe6 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Thu, 18 Mar 2021 13:28:19 -0500 Subject: [PATCH 1/3] feat: add `ExternalConfig.connection_id` property to connect to external sources --- google/cloud/bigquery/external_config.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/google/cloud/bigquery/external_config.py b/google/cloud/bigquery/external_config.py index 112dfdba4..d6a4195ef 100644 --- a/google/cloud/bigquery/external_config.py +++ b/google/cloud/bigquery/external_config.py @@ -760,6 +760,14 @@ def schema(self): prop = self._properties.get("schema", {}) return [SchemaField.from_api_repr(field) for field in prop.get("fields", [])] + @property + def connection_id(self): + return self._properties.get("connectionId") + + @connection_id.setter + def connectionid(self, value): + self._properties["connectionId"] = value + @schema.setter def schema(self, value): prop = value From 915462d41ada06cca06c79873f64cd87a4cd3226 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Fri, 19 Mar 2021 13:20:23 -0500 Subject: [PATCH 2/3] add tests --- google/cloud/bigquery/external_config.py | 9 +++++++++ tests/unit/test_external_config.py | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/google/cloud/bigquery/external_config.py b/google/cloud/bigquery/external_config.py index d6a4195ef..504b8f1d6 100644 --- a/google/cloud/bigquery/external_config.py +++ b/google/cloud/bigquery/external_config.py @@ -762,6 +762,15 @@ def schema(self): @property def connection_id(self): + """Optional[str]: [Experimental] ID of a BigQuery Connection API + resource. + + .. WARNING:: + + This feature is experimental. Pre-GA features may have limited + support, and changes to pre-GA features may not be compatible with + other pre-GA versions. + """ return self._properties.get("connectionId") @connection_id.setter diff --git a/tests/unit/test_external_config.py b/tests/unit/test_external_config.py index 4b6ef5118..3776aff39 100644 --- a/tests/unit/test_external_config.py +++ b/tests/unit/test_external_config.py @@ -74,6 +74,7 @@ def test_to_api_repr_base(self): ec.autodetect = True ec.ignore_unknown_values = False ec.compression = "compression" + ec.connection_id = "path/to/connection" ec.schema = [schema.SchemaField("full_name", "STRING", mode="REQUIRED")] exp_schema = { @@ -94,10 +95,17 @@ def test_to_api_repr_base(self): "autodetect": True, "ignoreUnknownValues": False, "compression": "compression", + "connectionId": "path/to/connection", "schema": exp_schema, } self.assertEqual(got_resource, exp_resource) + def test_connection_di(self): + ec = external_config.ExternalConfig("") + self.assertIsNone(ec.connection_id) + ec.connection_id = "path/to/connection" + self.assertEqual(ec.connection_id, "path/to/connection") + def test_schema_None(self): ec = external_config.ExternalConfig("") ec.schema = None From c922eb94bd4803a2b54bd68a8f5f7bb84a3b3574 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Fri, 19 Mar 2021 13:29:33 -0500 Subject: [PATCH 3/3] fix unit tests --- google/cloud/bigquery/external_config.py | 2 +- tests/unit/test_external_config.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google/cloud/bigquery/external_config.py b/google/cloud/bigquery/external_config.py index 504b8f1d6..59e4960f9 100644 --- a/google/cloud/bigquery/external_config.py +++ b/google/cloud/bigquery/external_config.py @@ -774,7 +774,7 @@ def connection_id(self): return self._properties.get("connectionId") @connection_id.setter - def connectionid(self, value): + def connection_id(self, value): self._properties["connectionId"] = value @schema.setter diff --git a/tests/unit/test_external_config.py b/tests/unit/test_external_config.py index 73ef4fb55..648a8717e 100644 --- a/tests/unit/test_external_config.py +++ b/tests/unit/test_external_config.py @@ -93,7 +93,7 @@ def test_to_api_repr_base(self): } self.assertEqual(got_resource, exp_resource) - def test_connection_di(self): + def test_connection_id(self): ec = external_config.ExternalConfig("") self.assertIsNone(ec.connection_id) ec.connection_id = "path/to/connection"