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

Fix for alter table ... rename statements on Snowflake #1324

Merged
merged 3 commits into from
Feb 28, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down
7 changes: 7 additions & 0 deletions plugins/snowflake/dbt/include/snowflake/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
2 changes: 1 addition & 1 deletion test/integration/024_custom_schema_test/models/view_3.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

{{ config(schema='test') }}
{{ config(schema='test', materialized='table') }}


with v1 as (
Expand Down
38 changes: 37 additions & 1 deletion test/integration/024_custom_schema_test/test_custom_schema.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_snowflake_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
])
Expand Down