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 ExternalConfig.connection_id property to connect to external sources #560

Merged
merged 4 commits into from Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions google/cloud/bigquery/external_config.py
Expand Up @@ -760,6 +760,23 @@ 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):
tswast marked this conversation as resolved.
Show resolved Hide resolved
"""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
def connection_id(self, value):
self._properties["connectionId"] = value

@schema.setter
def schema(self, value):
prop = value
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_external_config.py
Expand Up @@ -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 = {
Expand All @@ -87,10 +88,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_id(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
Expand Down