From 9c9c0d991a202a1555ae020084f8536f0b0595e0 Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Tue, 26 Feb 2019 13:08:28 -0500 Subject: [PATCH 1/3] (fixes #1316) Fix for alter table rename on Snowflake tables, added tests --- .../dbt/include/snowflake/macros/adapters.sql | 7 ++++ .../024_custom_schema_test/models/view_3.sql | 2 +- .../test_custom_schema.py | 38 ++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/plugins/snowflake/dbt/include/snowflake/macros/adapters.sql b/plugins/snowflake/dbt/include/snowflake/macros/adapters.sql index 05144c654b8..4e8c5f3fbdd 100644 --- a/plugins/snowflake/dbt/include/snowflake/macros/adapters.sql +++ b/plugins/snowflake/dbt/include/snowflake/macros/adapters.sql @@ -81,3 +81,10 @@ {% macro snowflake__current_timestamp() -%} convert_timezone('UTC', current_timestamp()) {%- endmacro %} + + +{% macro snowflake__rename_relation(from_relation, to_relation) -%} + {% call statement('rename_relation') -%} + alter table {{ from_relation }} rename to {{ to_relation }} + {%- endcall %} +{% endmacro %} diff --git a/test/integration/024_custom_schema_test/models/view_3.sql b/test/integration/024_custom_schema_test/models/view_3.sql index c208e5d32df..33931704248 100644 --- a/test/integration/024_custom_schema_test/models/view_3.sql +++ b/test/integration/024_custom_schema_test/models/view_3.sql @@ -1,5 +1,5 @@ -{{ config(schema='test') }} +{{ config(schema='test', materialized='table') }} with v1 as ( diff --git a/test/integration/024_custom_schema_test/test_custom_schema.py b/test/integration/024_custom_schema_test/test_custom_schema.py index 4a64d7e419f..2ca445f4dd5 100644 --- a/test/integration/024_custom_schema_test/test_custom_schema.py +++ b/test/integration/024_custom_schema_test/test_custom_schema.py @@ -1,5 +1,5 @@ from nose.plugins.attrib import attr -from test.integration.base import DBTIntegrationTest +from test.integration.base import DBTIntegrationTest, use_profile class TestCustomSchema(DBTIntegrationTest): @@ -85,6 +85,42 @@ def test__postgres__custom_schema_with_prefix(self): self.assertTablesEqual("agg","view_3", schema, xf_schema) +class TestCustomProjectSchemaWithPrefixSnowflake(DBTIntegrationTest): + + @property + def schema(self): + return "custom_schema_024" + + @property + def models(self): + return "test/integration/024_custom_schema_test/models" + + @property + def project_config(self): + return { + "models": { + "schema": "dbt_test" + } + } + + @use_profile('snowflake') + def test__snowflake__custom_schema_with_prefix(self): + self.use_default_project() + self.run_sql_file("test/integration/024_custom_schema_test/seed.sql") + + results = self.run_dbt() + self.assertEqual(len(results), 3) + + schema = self.unique_schema().upper() + v1_schema = "{}_DBT_TEST".format(schema) + v2_schema = "{}_CUSTOM".format(schema) + xf_schema = "{}_TEST".format(schema) + + self.assertTablesEqual("SEED","VIEW_1", schema, v1_schema) + self.assertTablesEqual("SEED","VIEW_2", schema, v2_schema) + self.assertTablesEqual("AGG","VIEW_3", schema, xf_schema) + + class TestCustomSchemaWithCustomMacro(DBTIntegrationTest): @property From f8dfe486538696ace519b4dee2f0f743891cae22 Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Tue, 26 Feb 2019 13:18:30 -0500 Subject: [PATCH 2/3] (fixes #1313) Show sources in resource count list during compilation --- core/dbt/compilation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/core/dbt/compilation.py b/core/dbt/compilation.py index 9f101c39222..a48a97b41ea 100644 --- a/core/dbt/compilation.py +++ b/core/dbt/compilation.py @@ -36,6 +36,7 @@ def print_compile_stats(stats): NodeType.Macro: 'macros', NodeType.Operation: 'operations', NodeType.Seed: 'seed files', + NodeType.Source: 'sources', } results = {k: 0 for k in names.keys()} From 72d6ee244693d2bbd4a3e469cf3d922adec09ff3 Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Wed, 27 Feb 2019 13:24:32 -0500 Subject: [PATCH 3/3] fix tests --- test/unit/test_snowflake_adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/test_snowflake_adapter.py b/test/unit/test_snowflake_adapter.py index 0ee65d05759..d97ee2b4c7e 100644 --- a/test/unit/test_snowflake_adapter.py +++ b/test/unit/test_snowflake_adapter.py @@ -125,7 +125,7 @@ def test_quoting_on_rename(self): ) self.mock_execute.assert_has_calls([ mock.call( - 'alter table "test_database"."test_schema".table_a rename to table_b', + 'alter table "test_database"."test_schema".table_a rename to "test_database"."test_schema".table_b', None ) ])