From 95b2a16b552d530e53ace86f32459f4d225e5134 Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Thu, 14 Dec 2017 13:46:50 -0500 Subject: [PATCH 1/2] Fixes already opened transaction issue For https://github.com/fishtown-analytics/dbt/issues/602 --- dbt/adapters/snowflake.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dbt/adapters/snowflake.py b/dbt/adapters/snowflake.py index 801628e2dbc..431f1b1c33f 100644 --- a/dbt/adapters/snowflake.py +++ b/dbt/adapters/snowflake.py @@ -147,7 +147,11 @@ def add_begin_query(cls, profile, name): def create_schema(cls, profile, schema, model_name=None): logger.debug('Creating schema "%s".', schema) sql = cls.get_create_schema_sql(schema) - return cls.add_query(profile, sql, model_name, select_schema=False) + res = cls.add_query(profile, sql, model_name, select_schema=False) + + cls.commit_if_has_connection(profile, model_name) + + return res @classmethod def get_existing_schemas(cls, profile, model_name=None): From 1b44f36271ea6c4aa04a3ec0b39f4f3c518c443d Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Thu, 14 Dec 2017 15:24:49 -0500 Subject: [PATCH 2/2] Fixes https://github.com/fishtown-analytics/dbt/issues/621 --- dbt/node_runners.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dbt/node_runners.py b/dbt/node_runners.py index 74c07434bcf..af62b461874 100644 --- a/dbt/node_runners.py +++ b/dbt/node_runners.py @@ -318,6 +318,13 @@ def safe_run_hooks(cls, project, adapter, flat_graph, hook_type): def create_schemas(cls, project, adapter, flat_graph): profile = project.run_environment() required_schemas = cls.get_model_schemas(flat_graph) + + # Snowflake needs to issue a "use {schema}" query, where schema + # is the one defined in the profile. Create this schema if it + # does not exist, otherwise subsequent queries will fail. Generally, + # dbt expects that this schema will exist anyway. + required_schemas.add(adapter.get_default_schema(profile)) + existing_schemas = set(adapter.get_existing_schemas(profile)) for schema in (required_schemas - existing_schemas):