diff --git a/CHANGELOG.md b/CHANGELOG.md index d1795f5127c..1c0fa34c628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ### Changes + - Support external BigQuery relations ([#828](https://github.com/fishtown-analytics/dbt/pull/828)) + - Added tox environments that have the user specify what tests should be run ([#837](https://github.com/fishtown-analytics/dbt/pull/837)) + - Set the TCP keepalive on redshift ([#826](https://github.com/fishtown-analytics/dbt/pull/826)) - Fix the error handling for profiles.yml validation ([#820](https://github.com/fishtown-analytics/dbt/pull/820)) - Make the `--threads` parameter actually change the number of threads used ([#819](https://github.com/fishtown-analytics/dbt/pull/819)) - Use Mapping instead of dict as the base class for APIObject ([#756](https://github.com/fishtown-analytics/dbt/pull/756)) diff --git a/dbt/adapters/bigquery/relation.py b/dbt/adapters/bigquery/relation.py index f0bb48c4309..1e696a848ee 100644 --- a/dbt/adapters/bigquery/relation.py +++ b/dbt/adapters/bigquery/relation.py @@ -3,6 +3,7 @@ class BigQueryRelation(DefaultRelation): + External = "external" DEFAULTS = { 'metadata': { @@ -54,7 +55,7 @@ class BigQueryRelation(DefaultRelation): }, }, 'type': { - 'enum': DefaultRelation.RelationTypes + [None], + 'enum': DefaultRelation.RelationTypes + [External, None], }, 'path': PATH_SCHEMA, 'include_policy': POLICY_SCHEMA, diff --git a/test/unit/test_bigquery_adapter.py b/test/unit/test_bigquery_adapter.py index 3f91ed5f6df..1ca78796141 100644 --- a/test/unit/test_bigquery_adapter.py +++ b/test/unit/test_bigquery_adapter.py @@ -4,6 +4,7 @@ import dbt.flags as flags from dbt.adapters.bigquery import BigQueryAdapter +from dbt.adapters.bigquery.relation import BigQueryRelation import dbt.exceptions from dbt.logger import GLOBAL_LOGGER as logger # noqa @@ -58,3 +59,88 @@ def test_acquire_connection_service_account_validations(self, mock_open_connecti self.fail('validation failed with unknown exception: {}'.format(str(e))) mock_open_connection.assert_called_once() + + +class TestBigQueryRelation(unittest.TestCase): + def setUp(self): + flags.STRICT_MODE = True + + def test_view_temp_relation(self): + kwargs = { + 'type': None, + 'path': { + 'project': 'test-project', + 'schema': 'test_schema', + 'identifier': 'my_view' + }, + 'table_name': 'my_view__dbt_tmp', + 'quote_policy': { + 'identifier': False + } + } + BigQueryRelation(**kwargs) + + def test_view_relation(self): + kwargs = { + 'type': 'view', + 'path': { + 'project': 'test-project', + 'schema': 'test_schema', + 'identifier': 'my_view' + }, + 'table_name': 'my_view', + 'quote_policy': { + 'identifier': True, + 'schema': True + } + } + BigQueryRelation(**kwargs) + + def test_table_relation(self): + kwargs = { + 'type': 'table', + 'path': { + 'project': 'test-project', + 'schema': 'test_schema', + 'identifier': 'generic_table' + }, + 'table_name': 'generic_table', + 'quote_policy': { + 'identifier': True, + 'schema': True + } + } + BigQueryRelation(**kwargs) + + def test_external_source_relation(self): + kwargs = { + 'type': 'external', + 'path': { + 'project': 'test-project', + 'schema': 'test_schema', + 'identifier': 'sheet' + }, + 'table_name': 'sheet', + 'quote_policy': { + 'identifier': True, + 'schema': True + } + } + BigQueryRelation(**kwargs) + + def test_invalid_relation(self): + kwargs = { + 'type': 'invalid-type', + 'path': { + 'project': 'test-project', + 'schema': 'test_schema', + 'identifier': 'my_invalid_id' + }, + 'table_name': 'my_invalid_id', + 'quote_policy': { + 'identifier': False, + 'schema': True + } + } + with self.assertRaises(dbt.exceptions.ValidationException): + BigQueryRelation(**kwargs)