Skip to content

Commit

Permalink
update snowflake connection to handle new closed state properly, rena…
Browse files Browse the repository at this point in the history
…me "warehouse" config key to "snowflake_warehouse", t ests
  • Loading branch information
Jacob Beck committed Nov 7, 2019
1 parent 6198584 commit c68154f
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 9 deletions.
4 changes: 2 additions & 2 deletions plugins/snowflake/dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def type(self):
return 'snowflake'

def _connection_keys(self):
return ('account', 'user', 'database', 'schema', 'warehouse', 'role',
'client_session_keep_alive')
return ('account', 'user', 'database', 'schema', 'snowflake_warehouse',
'role', 'client_session_keep_alive')

def auth_args(self):
# Pull all of the optional authentication args for the connector,
Expand Down
4 changes: 2 additions & 2 deletions plugins/snowflake/dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SnowflakeAdapter(SQLAdapter):

AdapterSpecificConfigs = frozenset(
{"transient", "cluster_by", "automatic_clustering", "secure",
"copy_grants", "warehouse"}
"copy_grants", "snowflake_warehouse"}
)

@classmethod
Expand Down Expand Up @@ -62,7 +62,7 @@ def _use_warehouse(self, warehouse: str):

def pre_model_hook(self, config: Mapping[str, Any]) -> Optional[str]:
default_warehouse = self.config.credentials.warehouse
warehouse = config.get('warehouse', default_warehouse)
warehouse = config.get('snowflake_warehouse', default_warehouse)
if warehouse == default_warehouse or warehouse is None:
return None
previous = self._get_warehouse()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{ config(warehouse='DBT_TEST_DOES_NOT_EXIST') }}
{{ config(snowflake_warehouse='DBT_TEST_DOES_NOT_EXIST') }}
select current_warehouse() as warehouse
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{ config(warehouse='DBT_TEST_ALT', materialized='table') }}
{{ config(snowflake_warehouse='DBT_TEST_ALT', materialized='table') }}
select current_warehouse() as warehouse
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ config(materialized='table') }}
select 'DBT_TEST_ALT' as warehouse
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ config(materialized='table') }}
select current_warehouse() as warehouse
35 changes: 34 additions & 1 deletion test/integration/050_warehouse_test/test_warehouses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os


class TestDebug(DBTIntegrationTest):
class TestModelWarehouse(DBTIntegrationTest):
@property
def schema(self):
return 'dbt_warehouse_050'
Expand All @@ -26,3 +26,36 @@ def test_snowflake_override_ok(self):
@use_profile('snowflake')
def test_snowflake_override_noexist(self):
self.run_dbt(['run', '--models', 'invalid_warehouse'], expect_pass=False)


class TestConfigWarehouse(DBTIntegrationTest):
@property
def schema(self):
return 'dbt_warehouse_050'

@property
def project_config(self):
return {
'source-paths': ['project-config-models'],
'models': {
'test': {
'snowflake_warehouse': 'DBT_TEST_ALT',
},
},
}

@staticmethod
def dir(value):
return os.path.normpath(value)

@property
def models(self):
return self.dir('models')

@use_profile('snowflake')
def test_snowflake_override_ok(self):
self.run_dbt([
'run',
'--models', 'override_warehouse', 'expected_warehouse',
])
self.assertManyRelationsEqual([['OVERRIDE_WAREHOUSE'], ['EXPECTED_WAREHOUSE']])
2 changes: 1 addition & 1 deletion test/integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def run_sql_common(self, sql, fetch, conn):
else:
return
except BaseException as e:
if conn.handle and conn.handle.closed != 0:
if conn.handle and not conn.handle.is_closed():
conn.handle.rollback()
print(sql)
print(e)
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 @@ -181,7 +181,7 @@ def _strip_transactions(self):

def test_pre_post_hooks_warehouse(self):
with self.current_warehouse('warehouse'):
config = {'warehouse': 'other_warehouse'}
config = {'snowflake_warehouse': 'other_warehouse'}
result = self.adapter.pre_model_hook(config)
self.assertIsNotNone(result)
calls = [
Expand Down

0 comments on commit c68154f

Please sign in to comment.