From 2b1378c2d24d6af3fb0e566da6ddafe28014ee05 Mon Sep 17 00:00:00 2001 From: Brian Abelson Date: Tue, 6 Feb 2018 15:39:53 -0500 Subject: [PATCH 01/11] tests working on newer postgres image --- Makefile | 5 +++++ test/setup_db.sh | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c6d937a9ba9..9189d061194 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,13 @@ test-integration: @echo "Integration test run starting..." @time docker-compose run test tox -e integration-postgres-py27,integration-postgres-py36,integration-snowflake-py27,integration-snowflake-py36,integration-bigquery-py27,integration-bigquery-py36 +test-integration-postgres: + @echo "Postgres integration tests run starting..." + @time docker-compose run test tox -e integration-postgres-py27,integration-postgres-py36 + test-new: @echo "Test run starting..." @echo "Changed test files:" @echo "${changed_tests}" @docker-compose run test /usr/src/app/test/runner.sh ${changed_tests} + diff --git a/test/setup_db.sh b/test/setup_db.sh index e315d76f02f..7a7c26aefea 100644 --- a/test/setup_db.sh +++ b/test/setup_db.sh @@ -1,11 +1,11 @@ set -x createdb dbt -psql -c "CREATE ROLE root WITH UNENCRYPTED PASSWORD 'password';" -U postgres +psql -c "CREATE ROLE root WITH PASSWORD 'password';" -U postgres psql -c "ALTER ROLE root WITH LOGIN;" -U postgres psql -c "GRANT CREATE, CONNECT ON DATABASE dbt TO root;" -U postgres -psql -c "CREATE ROLE noaccess WITH UNENCRYPTED PASSWORD 'password' NOSUPERUSER;" -U postgres; +psql -c "CREATE ROLE noaccess WITH PASSWORD 'password' NOSUPERUSER;" -U postgres; psql -c "ALTER ROLE noaccess WITH LOGIN;" -U postgres psql -c "GRANT CONNECT ON DATABASE dbt TO noaccess;" -U postgres; From 3726cd13bba39f5537e3c4beedb967b75319935b Mon Sep 17 00:00:00 2001 From: Brian Abelson Date: Thu, 8 Feb 2018 12:36:01 -0500 Subject: [PATCH 02/11] rename test --- .../026_timezones_test/models/timezones.sql | 10 ++++ .../026_timezones_test/test_timezones.py | 55 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 test/integration/026_timezones_test/models/timezones.sql create mode 100644 test/integration/026_timezones_test/test_timezones.py diff --git a/test/integration/026_timezones_test/models/timezones.sql b/test/integration/026_timezones_test/models/timezones.sql new file mode 100644 index 00000000000..87d565487e1 --- /dev/null +++ b/test/integration/026_timezones_test/models/timezones.sql @@ -0,0 +1,10 @@ + +{{ + config( + materialized='table' + ) +}} + +select + '{{ run_started_at.astimezone(modules.pytz.timezone("America/New_York")) }}' as run_started_at_est, + '{{ run_started_at }}' as run_started_at_utc diff --git a/test/integration/026_timezones_test/test_timezones.py b/test/integration/026_timezones_test/test_timezones.py new file mode 100644 index 00000000000..af995eaef31 --- /dev/null +++ b/test/integration/026_timezones_test/test_timezones.py @@ -0,0 +1,55 @@ +from freezegun import freeze_time +from nose.plugins.attrib import attr +from test.integration.base import DBTIntegrationTest + + +class TestTimezones(DBTIntegrationTest): + + def setUp(self): + DBTIntegrationTest.setUp(self) + + @property + def schema(self): + return "timezones_025" + + @property + def models(self): + return "test/integration/025_timezones_test/models" + + @property + def profile_config(self): + return { + 'test': { + 'outputs': { + 'dev': { + 'type': 'postgres', + 'threads': 1, + 'host': 'database', + 'port': 5432, + 'user': "root", + 'pass': "password", + 'dbname': 'dbt', + 'schema': self.unique_schema() + }, + }, + 'target': 'dev' + } + } + + @property + def query(self): + return """ + select + run_started_at_est, + run_started_at_utc + from {schema}.timezones + """.format(schema=self.unique_schema()) + + @freeze_time("2017-01-01 03:00:00", tz_offset=0) + @attr(type='postgres') + def test_run_started_at(self): + self.run_dbt(['run']) + result = self.run_sql(self.query, fetch='all')[0] + est, utc = result + self.assertEqual(utc, '2017-01-01 03:00:00+00:00') + self.assertEqual(est, '2016-12-31 22:00:00-05:00') From 4fb70c1c0d516374787e7a194d82ebd4fe682119 Mon Sep 17 00:00:00 2001 From: Brian Abelson Date: Thu, 8 Feb 2018 20:53:52 -0500 Subject: [PATCH 03/11] passing tests; breaking no other tests. looks good! --- dbt/context/common.py | 4 +-- dbt/contracts/graph/parsed.py | 1 + .../macros/materializations/bigquery.sql | 4 +-- .../macros/materializations/incremental.sql | 6 ++-- .../macros/materializations/table.sql | 2 +- .../macros/materializations/view.sql | 2 +- dbt/model.py | 1 + dbt/utils.py | 16 ++++++--- .../026_aliases_test/models/foo_alias.sql | 10 ++++++ .../026_aliases_test/models/ref_foo_alias.sql | 18 ++++++++++ .../test_aliases.py} | 33 +++++++++++-------- .../026_timezones_test/models/timezones.sql | 10 ------ 12 files changed, 69 insertions(+), 38 deletions(-) create mode 100644 test/integration/026_aliases_test/models/foo_alias.sql create mode 100644 test/integration/026_aliases_test/models/ref_foo_alias.sql rename test/integration/{026_timezones_test/test_timezones.py => 026_aliases_test/test_aliases.py} (58%) delete mode 100644 test/integration/026_timezones_test/models/timezones.sql diff --git a/dbt/context/common.py b/dbt/context/common.py index 072cb62a7e4..61115a0a24c 100644 --- a/dbt/context/common.py +++ b/dbt/context/common.py @@ -45,7 +45,7 @@ def __init__(self, model, adapter, profile): def wrap_with_profile_and_model_name(self, fn): def wrapped(*args, **kwargs): args = (self.profile,) + args - kwargs['model_name'] = self.model.get('name') + kwargs['model_name'] = self.model.get('alias') return getattr(self.adapter, fn)(*args, **kwargs) return wrapped @@ -55,7 +55,7 @@ def type(self): def commit(self): return self.adapter.commit_if_has_connection( - self.profile, self.model.get('name')) + self.profile, self.model.get('alias')) def _add_macros(context, model, flat_graph): diff --git a/dbt/contracts/graph/parsed.py b/dbt/contracts/graph/parsed.py index 570b73f25ed..64f5ce6a30e 100644 --- a/dbt/contracts/graph/parsed.py +++ b/dbt/contracts/graph/parsed.py @@ -31,6 +31,7 @@ Required('unique_id'): All(basestring, Length(min=1, max=255)), Required('fqn'): All(list, [All(basestring)]), Required('schema'): basestring, + Required('alias'): basestring, Required('refs'): [All(tuple)], diff --git a/dbt/include/global_project/macros/materializations/bigquery.sql b/dbt/include/global_project/macros/materializations/bigquery.sql index e61373a4634..e7e97084e9c 100644 --- a/dbt/include/global_project/macros/materializations/bigquery.sql +++ b/dbt/include/global_project/macros/materializations/bigquery.sql @@ -1,6 +1,6 @@ {% materialization view, adapter='bigquery' -%} - {%- set identifier = model['name'] -%} + {%- set identifier = model['alias'] -%} {%- set tmp_identifier = identifier + '__dbt_tmp' -%} {%- set non_destructive_mode = (flags.NON_DESTRUCTIVE == True) -%} {%- set existing = adapter.query_for_existing(schema) -%} @@ -18,7 +18,7 @@ {% materialization table, adapter='bigquery' -%} - {%- set identifier = model['name'] -%} + {%- set identifier = model['alias'] -%} {%- set tmp_identifier = identifier + '__dbt_tmp' -%} {%- set non_destructive_mode = (flags.NON_DESTRUCTIVE == True) -%} {%- set existing = adapter.query_for_existing(schema) -%} diff --git a/dbt/include/global_project/macros/materializations/incremental.sql b/dbt/include/global_project/macros/materializations/incremental.sql index 248249631e4..22c2da5b5a9 100644 --- a/dbt/include/global_project/macros/materializations/incremental.sql +++ b/dbt/include/global_project/macros/materializations/incremental.sql @@ -1,7 +1,7 @@ {% macro dbt__incremental_delete(schema, model) -%} {%- set unique_key = config.require('unique_key') -%} - {%- set identifier = model['name'] -%} + {%- set identifier = model['alias'] -%} delete from "{{ schema }}"."{{ identifier }}" @@ -16,8 +16,8 @@ {%- set sql_where = config.require('sql_where') -%} {%- set unique_key = config.get('unique_key') -%} - {%- set identifier = model['name'] -%} - {%- set tmp_identifier = model['name'] + '__dbt_incremental_tmp' -%} + {%- set identifier = model['alias'] -%} + {%- set tmp_identifier = identifier + '__dbt_incremental_tmp' -%} {%- set non_destructive_mode = (flags.NON_DESTRUCTIVE == True) -%} {%- set full_refresh_mode = (flags.FULL_REFRESH == True) -%} diff --git a/dbt/include/global_project/macros/materializations/table.sql b/dbt/include/global_project/macros/materializations/table.sql index 96691afdbec..dcc35cc2d3a 100644 --- a/dbt/include/global_project/macros/materializations/table.sql +++ b/dbt/include/global_project/macros/materializations/table.sql @@ -1,5 +1,5 @@ {% materialization table, default %} - {%- set identifier = model['name'] -%} + {%- set identifier = model['alias'] -%} {%- set tmp_identifier = identifier + '__dbt_tmp' -%} {%- set non_destructive_mode = (flags.NON_DESTRUCTIVE == True) -%} {%- set existing = adapter.query_for_existing(schema) -%} diff --git a/dbt/include/global_project/macros/materializations/view.sql b/dbt/include/global_project/macros/materializations/view.sql index 16612b29069..f1868f4e70f 100644 --- a/dbt/include/global_project/macros/materializations/view.sql +++ b/dbt/include/global_project/macros/materializations/view.sql @@ -1,6 +1,6 @@ {%- materialization view, default -%} - {%- set identifier = model['name'] -%} + {%- set identifier = model['alias'] -%} {%- set tmp_identifier = identifier + '__dbt_tmp' -%} {%- set non_destructive_mode = (flags.NON_DESTRUCTIVE == True) -%} {%- set existing = adapter.query_for_existing(schema) -%} diff --git a/dbt/model.py b/dbt/model.py index 298070f1b2e..745c4ee9d63 100644 --- a/dbt/model.py +++ b/dbt/model.py @@ -13,6 +13,7 @@ class SourceConfig(object): AppendListFields = ['pre-hook', 'post-hook'] ExtendDictFields = ['vars'] ClobberFields = [ + 'alias', 'schema', 'enabled', 'materialized', diff --git a/dbt/utils.py b/dbt/utils.py index 7830b6b337b..2cada5644e1 100644 --- a/dbt/utils.py +++ b/dbt/utils.py @@ -12,6 +12,7 @@ DBTConfigKeys = [ + 'alias', 'schema', 'enabled', 'materialized', @@ -38,11 +39,14 @@ def __init__(self, profile, adapter, node, use_temp=False): self.node = node self.schema = node.get('schema') self.name = node.get('name') + # set alias, defaults to name + self.alias = get_alias(node) + self.node['alias'] = get_alias(node) if use_temp: self.table = self._get_table_name(node) else: - self.table = self.name + self.table = self.alias self.materialized = get_materialization(node) self.sql = node.get('injected_sql') @@ -70,11 +74,11 @@ def final_name(self): msg = "final_name() was called on an ephemeral model" dbt.exceptions.raise_compiler_error(msg, self.node) else: - return self.do_quote(self.schema, self.name) + return self.do_quote(self.schema, self.alias) def __repr__(self): if self.materialized == 'ephemeral': - return '__dbt__CTE__{}'.format(self.name) + return '__dbt__CTE__{}'.format(self.alias) else: return self.do_quote(self.schema, self.table) @@ -99,7 +103,7 @@ def get_model_name_or_none(model): elif isinstance(model, basestring): name = model elif isinstance(model, dict): - name = model.get('name') + name = get_alias(model) else: name = model.nice_name return name @@ -115,7 +119,7 @@ def compiler_warning(model, msg): def model_immediate_name(model, non_destructive): "The name of the model table/view within the transaction" - model_name = model.get('name') + model_name = get_alias(model) if non_destructive or get_materialization(model) == 'incremental': return model_name else: @@ -318,6 +322,8 @@ def is_blocking_dependency(node): def get_materialization(node): return node.get('config', {}).get('materialized') +def get_alias(node): + return node.get('config', {}).get('alias', node.get('name')) def is_enabled(node): return node.get('config', {}).get('enabled') is True diff --git a/test/integration/026_aliases_test/models/foo_alias.sql b/test/integration/026_aliases_test/models/foo_alias.sql new file mode 100644 index 00000000000..358eb8032fe --- /dev/null +++ b/test/integration/026_aliases_test/models/foo_alias.sql @@ -0,0 +1,10 @@ + +{{ + config( + alias='foo', + materialized='table' + ) +}} + +SELECT + '{{ this.alias }}' as "tablename" diff --git a/test/integration/026_aliases_test/models/ref_foo_alias.sql b/test/integration/026_aliases_test/models/ref_foo_alias.sql new file mode 100644 index 00000000000..58ff4f90c45 --- /dev/null +++ b/test/integration/026_aliases_test/models/ref_foo_alias.sql @@ -0,0 +1,18 @@ + +{{ + config( + materialized='table' + ) +}} + +WITH trigger_ref AS ( + SELECT + * + FROM + -- we should by able to still ref a model by it's filepath + {{ ref('foo_alias') }} +) + +SELECT + -- this name should still the filename + '{{ this.alias }}' as "tablename" \ No newline at end of file diff --git a/test/integration/026_timezones_test/test_timezones.py b/test/integration/026_aliases_test/test_aliases.py similarity index 58% rename from test/integration/026_timezones_test/test_timezones.py rename to test/integration/026_aliases_test/test_aliases.py index af995eaef31..a6a4b5488e0 100644 --- a/test/integration/026_timezones_test/test_timezones.py +++ b/test/integration/026_aliases_test/test_aliases.py @@ -1,20 +1,19 @@ -from freezegun import freeze_time from nose.plugins.attrib import attr from test.integration.base import DBTIntegrationTest -class TestTimezones(DBTIntegrationTest): +class TestAliases(DBTIntegrationTest): def setUp(self): DBTIntegrationTest.setUp(self) @property def schema(self): - return "timezones_025" + return "aliases_026" @property def models(self): - return "test/integration/025_timezones_test/models" + return "test/integration/026_aliases_test/models" @property def profile_config(self): @@ -37,19 +36,25 @@ def profile_config(self): } @property - def query(self): + def query_foo_alias(self): return """ select - run_started_at_est, - run_started_at_utc - from {schema}.timezones + tablename + from {schema}.foo + """.format(schema=self.unique_schema()) + + @property + def query_ref_foo_alias(self): + return """ + select + tablename + from {schema}.ref_foo_alias """.format(schema=self.unique_schema()) - @freeze_time("2017-01-01 03:00:00", tz_offset=0) @attr(type='postgres') - def test_run_started_at(self): + def test__alias_model_name(self): self.run_dbt(['run']) - result = self.run_sql(self.query, fetch='all')[0] - est, utc = result - self.assertEqual(utc, '2017-01-01 03:00:00+00:00') - self.assertEqual(est, '2016-12-31 22:00:00-05:00') + result = self.run_sql(self.query_foo_alias, fetch='all')[0][0] + self.assertEqual(result, 'foo') + result = self.run_sql(self.query_ref_foo_alias, fetch='all')[0][0] + self.assertEqual(result, 'ref_foo_alias') diff --git a/test/integration/026_timezones_test/models/timezones.sql b/test/integration/026_timezones_test/models/timezones.sql deleted file mode 100644 index 87d565487e1..00000000000 --- a/test/integration/026_timezones_test/models/timezones.sql +++ /dev/null @@ -1,10 +0,0 @@ - -{{ - config( - materialized='table' - ) -}} - -select - '{{ run_started_at.astimezone(modules.pytz.timezone("America/New_York")) }}' as run_started_at_est, - '{{ run_started_at }}' as run_started_at_utc From 76ced759513faa5dabb3d6567ff7105c91055854 Mon Sep 17 00:00:00 2001 From: Brian Abelson Date: Thu, 8 Feb 2018 21:08:07 -0500 Subject: [PATCH 04/11] cleanup and typos --- Makefile | 4 ---- test/integration/026_aliases_test/models/ref_foo_alias.sql | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 9189d061194..55f9a5e252b 100644 --- a/Makefile +++ b/Makefile @@ -17,10 +17,6 @@ test-integration: @echo "Integration test run starting..." @time docker-compose run test tox -e integration-postgres-py27,integration-postgres-py36,integration-snowflake-py27,integration-snowflake-py36,integration-bigquery-py27,integration-bigquery-py36 -test-integration-postgres: - @echo "Postgres integration tests run starting..." - @time docker-compose run test tox -e integration-postgres-py27,integration-postgres-py36 - test-new: @echo "Test run starting..." @echo "Changed test files:" diff --git a/test/integration/026_aliases_test/models/ref_foo_alias.sql b/test/integration/026_aliases_test/models/ref_foo_alias.sql index 58ff4f90c45..2839e613fb3 100644 --- a/test/integration/026_aliases_test/models/ref_foo_alias.sql +++ b/test/integration/026_aliases_test/models/ref_foo_alias.sql @@ -9,10 +9,10 @@ WITH trigger_ref AS ( SELECT * FROM - -- we should by able to still ref a model by it's filepath + -- we should still be able to ref a model by its filepath {{ ref('foo_alias') }} ) SELECT - -- this name should still the filename + -- this name should still be the filename '{{ this.alias }}' as "tablename" \ No newline at end of file From 81e644a943b0301a8a30457fe641cead484f6d7e Mon Sep 17 00:00:00 2001 From: Brian Abelson Date: Thu, 8 Feb 2018 21:08:33 -0500 Subject: [PATCH 05/11] extra line --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 55f9a5e252b..c6d937a9ba9 100644 --- a/Makefile +++ b/Makefile @@ -22,4 +22,3 @@ test-new: @echo "Changed test files:" @echo "${changed_tests}" @docker-compose run test /usr/src/app/test/runner.sh ${changed_tests} - From ecb7c861d133d2e3b48b680162952ff65b2b535a Mon Sep 17 00:00:00 2001 From: Brian Abelson Date: Thu, 8 Feb 2018 23:05:41 -0500 Subject: [PATCH 06/11] make alias optional, fix parser tests --- dbt/contracts/graph/parsed.py | 4 ++-- test/unit/test_parser.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/dbt/contracts/graph/parsed.py b/dbt/contracts/graph/parsed.py index 64f5ce6a30e..2539b66bb70 100644 --- a/dbt/contracts/graph/parsed.py +++ b/dbt/contracts/graph/parsed.py @@ -1,4 +1,4 @@ -from voluptuous import Schema, Required, All, Any, Length, ALLOW_EXTRA +from voluptuous import Schema, Required, Optional, All, Any, Length, ALLOW_EXTRA import dbt.exceptions @@ -31,7 +31,7 @@ Required('unique_id'): All(basestring, Length(min=1, max=255)), Required('fqn'): All(list, [All(basestring)]), Required('schema'): basestring, - Required('alias'): basestring, + Optional('alias'): basestring, Required('refs'): [All(tuple)], diff --git a/test/unit/test_parser.py b/test/unit/test_parser.py index d20c4b3ae27..80ea7956145 100644 --- a/test/unit/test_parser.py +++ b/test/unit/test_parser.py @@ -86,6 +86,7 @@ def test__single_model(self): 'snowplow': self.snowplow_project_config}), { 'model.root.model_one': { + 'alias': 'model_one', 'name': 'model_one', 'schema': 'analytics', 'resource_type': 'model', @@ -144,6 +145,7 @@ def test__single_model__nested_configuration(self): 'snowplow': self.snowplow_project_config}), { 'model.root.model_one': { + 'alias': 'model_one', 'name': 'model_one', 'schema': 'analytics', 'resource_type': 'model', @@ -185,6 +187,7 @@ def test__empty_model(self): {'root': self.root_project_config}), { 'model.root.model_one': { + 'alias': 'model_one', 'name': 'model_one', 'schema': 'analytics', 'resource_type': 'model', @@ -235,6 +238,7 @@ def test__simple_dependency(self): 'snowplow': self.snowplow_project_config}), { 'model.root.base': { + 'alias': 'base', 'name': 'base', 'schema': 'analytics', 'resource_type': 'model', @@ -256,6 +260,7 @@ def test__simple_dependency(self): models, 'base').get('raw_sql') }, 'model.root.events_tx': { + 'alias': 'events_tx', 'name': 'events_tx', 'schema': 'analytics', 'resource_type': 'model', @@ -334,6 +339,7 @@ def test__multiple_dependencies(self): 'snowplow': self.snowplow_project_config}), { 'model.root.events': { + 'alias': 'events', 'name': 'events', 'schema': 'analytics', 'resource_type': 'model', @@ -355,6 +361,7 @@ def test__multiple_dependencies(self): models, 'events').get('raw_sql') }, 'model.root.sessions': { + 'alias': 'sessions', 'name': 'sessions', 'schema': 'analytics', 'resource_type': 'model', @@ -376,6 +383,7 @@ def test__multiple_dependencies(self): models, 'sessions').get('raw_sql') }, 'model.root.events_tx': { + 'alias': 'events_tx', 'name': 'events_tx', 'schema': 'analytics', 'resource_type': 'model', @@ -397,6 +405,7 @@ def test__multiple_dependencies(self): models, 'events_tx').get('raw_sql') }, 'model.root.sessions_tx': { + 'alias': 'sessions_tx', 'name': 'sessions_tx', 'schema': 'analytics', 'resource_type': 'model', @@ -418,6 +427,7 @@ def test__multiple_dependencies(self): models, 'sessions_tx').get('raw_sql') }, 'model.root.multi': { + 'alias': 'multi', 'name': 'multi', 'schema': 'analytics', 'resource_type': 'model', @@ -498,6 +508,7 @@ def test__multiple_dependencies__packages(self): 'snowplow': self.snowplow_project_config}), { 'model.snowplow.events': { + 'alias': 'events', 'name': 'events', 'schema': 'analytics', 'resource_type': 'model', @@ -519,6 +530,7 @@ def test__multiple_dependencies__packages(self): models, 'events').get('raw_sql') }, 'model.snowplow.sessions': { + 'alias': 'sessions', 'name': 'sessions', 'schema': 'analytics', 'resource_type': 'model', @@ -540,6 +552,7 @@ def test__multiple_dependencies__packages(self): models, 'sessions').get('raw_sql') }, 'model.snowplow.events_tx': { + 'alias': 'events_tx', 'name': 'events_tx', 'schema': 'analytics', 'resource_type': 'model', @@ -561,6 +574,7 @@ def test__multiple_dependencies__packages(self): models, 'events_tx').get('raw_sql') }, 'model.snowplow.sessions_tx': { + 'alias': 'sessions_tx', 'name': 'sessions_tx', 'schema': 'analytics', 'resource_type': 'model', @@ -582,6 +596,7 @@ def test__multiple_dependencies__packages(self): models, 'sessions_tx').get('raw_sql') }, 'model.root.multi': { + 'alias': 'multi', 'name': 'multi', 'schema': 'analytics', 'resource_type': 'model', @@ -766,6 +781,7 @@ def test__in_model_config(self): 'snowplow': self.snowplow_project_config}), { 'model.root.model_one': { + 'alias': 'model_one', 'name': 'model_one', 'schema': 'analytics', 'resource_type': 'model', @@ -848,6 +864,7 @@ def test__root_project_config(self): 'snowplow': self.snowplow_project_config}), { 'model.root.table': { + 'alias': 'table', 'name': 'table', 'schema': 'analytics', 'resource_type': 'model', @@ -869,6 +886,7 @@ def test__root_project_config(self): models, 'table').get('raw_sql') }, 'model.root.ephemeral': { + 'alias': 'ephemeral', 'name': 'ephemeral', 'schema': 'analytics', 'resource_type': 'model', @@ -890,6 +908,7 @@ def test__root_project_config(self): models, 'ephemeral').get('raw_sql') }, 'model.root.view': { + 'alias': 'view', 'name': 'view', 'schema': 'analytics', 'resource_type': 'model', @@ -1039,6 +1058,7 @@ def test__other_project_config(self): 'snowplow': self.snowplow_project_config}), { 'model.root.table': { + 'alias': 'table', 'name': 'table', 'schema': 'analytics', 'resource_type': 'model', @@ -1060,6 +1080,7 @@ def test__other_project_config(self): models, 'table').get('raw_sql') }, 'model.root.ephemeral': { + 'alias': 'ephemeral', 'name': 'ephemeral', 'schema': 'analytics', 'resource_type': 'model', @@ -1081,6 +1102,7 @@ def test__other_project_config(self): models, 'ephemeral').get('raw_sql') }, 'model.root.view': { + 'alias': 'view', 'name': 'view', 'schema': 'analytics', 'resource_type': 'model', @@ -1102,6 +1124,7 @@ def test__other_project_config(self): models, 'view').get('raw_sql') }, 'model.snowplow.multi_sort': { + 'alias': 'multi_sort', 'name': 'multi_sort', 'schema': 'analytics', 'resource_type': 'model', @@ -1154,6 +1177,7 @@ def test__simple_schema_test(self): 'snowplow': self.snowplow_project_config}), { 'test.root.not_null_model_one_id': { + 'alias': 'not_null_model_one_id', 'name': 'not_null_model_one_id', 'schema': 'analytics', 'resource_type': 'test', @@ -1175,6 +1199,7 @@ def test__simple_schema_test(self): 'raw_sql': not_null_sql, }, 'test.root.unique_model_one_id': { + 'alias': 'unique_model_one_id', 'name': 'unique_model_one_id', 'schema': 'analytics', 'resource_type': 'test', @@ -1195,6 +1220,7 @@ def test__simple_schema_test(self): 'raw_sql': unique_sql, }, 'test.root.accepted_values_model_one_id__a__b': { + 'alias': 'accepted_values_model_one_id__a__b', 'name': 'accepted_values_model_one_id__a__b', 'schema': 'analytics', 'resource_type': 'test', @@ -1217,6 +1243,7 @@ def test__simple_schema_test(self): 'raw_sql': accepted_values_sql, }, 'test.root.relationships_model_one_id__id__ref_model_two_': { + 'alias': 'relationships_model_one_id__id__ref_model_two_', 'name': 'relationships_model_one_id__id__ref_model_two_', 'schema': 'analytics', 'resource_type': 'test', @@ -1309,6 +1336,7 @@ def test__simple_data_test(self): 'snowplow': self.snowplow_project_config}), { 'test.root.no_events': { + 'alias': 'no_events', 'name': 'no_events', 'schema': 'analytics', 'resource_type': 'test', @@ -1424,6 +1452,7 @@ def test__simple_macro_used_in_model(self): 'snowplow': self.snowplow_project_config}), { 'model.root.model_one': { + 'alias': 'model_one', 'name': 'model_one', 'schema': 'analytics', 'resource_type': 'model', @@ -1466,6 +1495,7 @@ def test__macro_no_explicit_project_used_in_model(self): 'snowplow': self.snowplow_project_config}), { 'model.root.model_one': { + 'alias': 'model_one', 'name': 'model_one', 'schema': 'analytics', 'resource_type': 'model', From 69e6c9afcbbec461f8f58416fa7cbc93b9bcb345 Mon Sep 17 00:00:00 2001 From: Brian Abelson Date: Mon, 12 Feb 2018 12:30:11 -0500 Subject: [PATCH 07/11] add requested changes --- dbt/adapters/bigquery.py | 2 +- dbt/context/common.py | 4 ++-- dbt/ui/printer.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dbt/adapters/bigquery.py b/dbt/adapters/bigquery.py index 21d3111b394..5449a14b608 100644 --- a/dbt/adapters/bigquery.py +++ b/dbt/adapters/bigquery.py @@ -240,7 +240,7 @@ def execute_model(cls, profile, model, materialization, model_name=None): if flags.STRICT_MODE: connection = cls.get_connection(profile, model.get('name')) validate_connection(connection) - cls.release_connection(profile, model.get('name')) + cls.release_connection(profile, model.get('alias')) model_name = model.get('name') model_schema = model.get('schema') diff --git a/dbt/context/common.py b/dbt/context/common.py index 61115a0a24c..072cb62a7e4 100644 --- a/dbt/context/common.py +++ b/dbt/context/common.py @@ -45,7 +45,7 @@ def __init__(self, model, adapter, profile): def wrap_with_profile_and_model_name(self, fn): def wrapped(*args, **kwargs): args = (self.profile,) + args - kwargs['model_name'] = self.model.get('alias') + kwargs['model_name'] = self.model.get('name') return getattr(self.adapter, fn)(*args, **kwargs) return wrapped @@ -55,7 +55,7 @@ def type(self): def commit(self): return self.adapter.commit_if_has_connection( - self.profile, self.model.get('alias')) + self.profile, self.model.get('name')) def _add_macros(context, model, flat_graph): diff --git a/dbt/ui/printer.py b/dbt/ui/printer.py index 33904c1c2b4..592cb6f5859 100644 --- a/dbt/ui/printer.py +++ b/dbt/ui/printer.py @@ -139,7 +139,7 @@ def print_test_result_line(result, schema_name, index, total): raise RuntimeError("unexpected status: {}".format(result.status)) print_fancy_output_line( - "{info} {name}".format(info=info, name=model.get('name')), + "{info} {name}".format(info=info, name=model.get('alias')), color(info), index, total, @@ -156,7 +156,7 @@ def print_model_result_line(result, schema_name, index, total): info=info, model_type=get_materialization(model), schema=schema_name, - relation=model.get('name')), + relation=model.get('alias')), status, index, total, From 75b91a83e8a74a18528afa2d3be50f5dc0a08cf1 Mon Sep 17 00:00:00 2001 From: Brian Abelson Date: Thu, 22 Feb 2018 13:33:46 -0500 Subject: [PATCH 08/11] fix describe_node --- dbt/node_runners.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt/node_runners.py b/dbt/node_runners.py index fe7c7132df7..c7109aa82ea 100644 --- a/dbt/node_runners.py +++ b/dbt/node_runners.py @@ -370,7 +370,7 @@ def after_hooks(cls, project, adapter, results, flat_graph, elapsed): def describe_node(self): materialization = dbt.utils.get_materialization(self.node) schema_name = self.node.get('schema') - node_name = self.node.get('name') + node_name = self.node.get('alias') return "{} model {}.{}".format(materialization, schema_name, node_name) From b11ebb0005ed6e38f889d5178b763ea90f8d8dd3 Mon Sep 17 00:00:00 2001 From: Brian Abelson Date: Thu, 22 Feb 2018 13:42:27 -0500 Subject: [PATCH 09/11] cleanup --- dbt/node_runners.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dbt/node_runners.py b/dbt/node_runners.py index c7109aa82ea..de334a4f455 100644 --- a/dbt/node_runners.py +++ b/dbt/node_runners.py @@ -371,7 +371,6 @@ def describe_node(self): materialization = dbt.utils.get_materialization(self.node) schema_name = self.node.get('schema') node_name = self.node.get('alias') - return "{} model {}.{}".format(materialization, schema_name, node_name) def print_start_line(self): From a2b5f73e57a24a53d81132187967a6371257f2f1 Mon Sep 17 00:00:00 2001 From: Brian Abelson Date: Wed, 28 Feb 2018 14:51:22 -0500 Subject: [PATCH 10/11] fix logging line --- dbt/parser.py | 2 +- dbt/utils.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dbt/parser.py b/dbt/parser.py index 128d296fb8a..ce7fd3c4a26 100644 --- a/dbt/parser.py +++ b/dbt/parser.py @@ -219,7 +219,7 @@ def parse_node(node, node_path, root_project_config, package_project_config, profile = dbt.utils.get_profile_from_project(root_project_config) default_schema = profile.get('schema', 'public') node['schema'] = default_schema - + node['alias'] = dbt.utils.get_alias(node) context = dbt.context.parser.generate(node, root_project_config, {"macros": macros}) diff --git a/dbt/utils.py b/dbt/utils.py index 2cada5644e1..dc0665432d4 100644 --- a/dbt/utils.py +++ b/dbt/utils.py @@ -39,6 +39,7 @@ def __init__(self, profile, adapter, node, use_temp=False): self.node = node self.schema = node.get('schema') self.name = node.get('name') + # set alias, defaults to name self.alias = get_alias(node) self.node['alias'] = get_alias(node) @@ -48,6 +49,7 @@ def __init__(self, profile, adapter, node, use_temp=False): else: self.table = self.alias + self.materialized = get_materialization(node) self.sql = node.get('injected_sql') From 5040c88134682e2e52c0e1e332c39fc86b0dfcf1 Mon Sep 17 00:00:00 2001 From: Brian Abelson Date: Wed, 28 Feb 2018 15:02:06 -0500 Subject: [PATCH 11/11] try to get alias from config --- dbt/node_runners.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt/node_runners.py b/dbt/node_runners.py index 90a4f3c00b5..1d487a1d0cf 100644 --- a/dbt/node_runners.py +++ b/dbt/node_runners.py @@ -378,7 +378,7 @@ def after_hooks(cls, project, adapter, results, flat_graph, elapsed): def describe_node(self): materialization = dbt.utils.get_materialization(self.node) schema_name = self.node.get('schema') - node_name = self.node.get('alias') + node_name = dbt.utils.get_alias(self.node) return "{} model {}.{}".format(materialization, schema_name, node_name) def print_start_line(self):