From c0ceaee122eea6ccc09d7dfe37966a06c678d7e4 Mon Sep 17 00:00:00 2001 From: Jacob Beck Date: Wed, 25 Mar 2020 10:38:50 -0600 Subject: [PATCH] Add support for source aliases --- CHANGELOG.md | 1 + core/dbt/parser/schemas.py | 1 + test/integration/022_bigquery_test/models/schema.yml | 9 +++++++++ test/integration/022_bigquery_test/models/view_model.sql | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf9d3e22972..c0984e2fbb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Added --fail-fast argument for dbt run and dbt test to fail on first test failure or runtime error. ([#1649](https://github.com/fishtown-analytics/dbt/issues/1649)) - Support for appending query comments to SQL queries. ([#2138](https://github.com/fishtown-analytics/dbt/issues/2138)) - Added a `get-manifest` API call. ([#2168](https://github.com/fishtown-analytics/dbt/issues/2168), [#2232](https://github.com/fishtown-analytics/dbt/pull/2232)) +- Support adapter-specific aliases (like `project` and `dataset` on BigQuery) in source definitions. ([#2133](https://github.com/fishtown-analytics/dbt/issues/2133), [#2244](https://github.com/fishtown-analytics/dbt/pull/2244)) ### Fixes - When a jinja value is undefined, give a helpful error instead of failing with cryptic "cannot pickle ParserMacroCapture" errors ([#2110](https://github.com/fishtown-analytics/dbt/issues/2110), [#2184](https://github.com/fishtown-analytics/dbt/pull/2184)) diff --git a/core/dbt/parser/schemas.py b/core/dbt/parser/schemas.py index 5fc7aae1fef..8c3d6db355c 100644 --- a/core/dbt/parser/schemas.py +++ b/core/dbt/parser/schemas.py @@ -495,6 +495,7 @@ def get_unparsed_target(self) -> Iterable[SourceTarget]: for data in self.get_key_dicts(): try: + data = self.project.credentials.translate_aliases(data) data = self._renderer.render_schema_source(data) source = UnparsedSourceDefinition.from_dict(data) except (ValidationError, JSONValidationException) as exc: diff --git a/test/integration/022_bigquery_test/models/schema.yml b/test/integration/022_bigquery_test/models/schema.yml index 031753900d4..68625ffc68d 100644 --- a/test/integration/022_bigquery_test/models/schema.yml +++ b/test/integration/022_bigquery_test/models/schema.yml @@ -49,3 +49,12 @@ models: - was_materialized: name: fUnKyCaSe type: view + + +sources: + - name: raw + project: "{{ target.database }}" + dataset: "{{ target.schema }}" + tables: + - name: seed + identifier: data_seed diff --git a/test/integration/022_bigquery_test/models/view_model.sql b/test/integration/022_bigquery_test/models/view_model.sql index dd926ba11e0..bacdaf874ea 100644 --- a/test/integration/022_bigquery_test/models/view_model.sql +++ b/test/integration/022_bigquery_test/models/view_model.sql @@ -11,4 +11,4 @@ select current_date as updated_at, dupe -from {{ ref('data_seed') }} +from {{ source('raw', 'seed') }}