-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Quote databases properly (#1396) #1402
Changes from all commits
97a6a51
d515903
fc4fc57
3188aea
8b58b20
2834f2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{%- set tgt = ref('seed') -%} | ||
{%- set got = adapter.get_relation(database=tgt.database, schema=tgt.schema, identifier=tgt.identifier) | string -%} | ||
{% set replaced = got.replace('"', '-') %} | ||
{% set expected = "-" + tgt.database.upper() + '-.-' + tgt.schema.upper() + '-.-' + tgt.identifier.upper() + '-' %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
with cte as ( | ||
select '{{ replaced }}' as name | ||
) | ||
select * from cte where name not like '{{ expected }}' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
{# | ||
We are running against a database that must be quoted. | ||
These calls ensure that we trigger an error if we're failing to quote at parse-time | ||
#} | ||
{% do adapter.already_exists(this.schema, this.table) %} | ||
{% do adapter.get_relation(this.database, this.schema, this.table) %} | ||
select * from {{ ref('seed') }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{{ | ||
config(database=var('alternate_db')) | ||
}} | ||
|
||
select * from {{ ref('seed') }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
from nose.plugins.attrib import attr | ||
from test.integration.base import DBTIntegrationTest | ||
|
||
import os | ||
|
||
|
||
class BaseOverrideDatabase(DBTIntegrationTest): | ||
setup_alternate_db = True | ||
|
@@ -12,6 +14,45 @@ def schema(self): | |
def models(self): | ||
return "test/integration/040_override_database_test/models" | ||
|
||
@property | ||
def alternative_database(self): | ||
if self.adapter_type == 'snowflake': | ||
return os.getenv('SNOWFLAKE_TEST_DATABASE') | ||
else: | ||
return super(BaseOverrideDatabase, self).alternative_database | ||
|
||
def snowflake_profile(self): | ||
return { | ||
'config': { | ||
'send_anonymous_usage_stats': False | ||
}, | ||
'test': { | ||
'outputs': { | ||
'default2': { | ||
'type': 'snowflake', | ||
'threads': 4, | ||
'account': os.getenv('SNOWFLAKE_TEST_ACCOUNT'), | ||
'user': os.getenv('SNOWFLAKE_TEST_USER'), | ||
'password': os.getenv('SNOWFLAKE_TEST_PASSWORD'), | ||
'database': os.getenv('SNOWFLAKE_TEST_QUOTED_DATABASE'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you update https://github.com/fishtown-analytics/dbt/blob/dev/wilt-chamberlain/test.env.sample accordingly? |
||
'schema': self.unique_schema(), | ||
'warehouse': os.getenv('SNOWFLAKE_TEST_WAREHOUSE'), | ||
}, | ||
'noaccess': { | ||
'type': 'snowflake', | ||
'threads': 4, | ||
'account': os.getenv('SNOWFLAKE_TEST_ACCOUNT'), | ||
'user': 'noaccess', | ||
'password': 'password', | ||
'database': os.getenv('SNOWFLAKE_TEST_DATABASE'), | ||
'schema': self.unique_schema(), | ||
'warehouse': os.getenv('SNOWFLAKE_TEST_WAREHOUSE'), | ||
} | ||
}, | ||
'target': 'default2' | ||
} | ||
} | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
|
@@ -20,9 +61,15 @@ def project_config(self): | |
'vars': { | ||
'alternate_db': self.alternative_database, | ||
}, | ||
}, | ||
'quoting': { | ||
'database': True, | ||
} | ||
} | ||
|
||
def run_dbt_notstrict(self, args): | ||
return self.run_dbt(args, strict=False) | ||
|
||
|
||
class TestModelOverride(BaseOverrideDatabase): | ||
def run_database_override(self): | ||
|
@@ -31,9 +78,9 @@ def run_database_override(self): | |
else: | ||
func = lambda x: x | ||
|
||
self.run_dbt(['seed']) | ||
self.run_dbt_notstrict(['seed']) | ||
|
||
self.assertEqual(len(self.run_dbt(['run'])), 4) | ||
self.assertEqual(len(self.run_dbt_notstrict(['run'])), 4) | ||
self.assertManyRelationsEqual([ | ||
(func('seed'), self.unique_schema(), self.default_database), | ||
(func('view_2'), self.unique_schema(), self.alternative_database), | ||
|
@@ -71,9 +118,9 @@ def run_database_override(self): | |
}, | ||
} | ||
}) | ||
self.run_dbt(['seed']) | ||
self.run_dbt_notstrict(['seed']) | ||
|
||
self.assertEqual(len(self.run_dbt(['run'])), 4) | ||
self.assertEqual(len(self.run_dbt_notstrict(['run'])), 4) | ||
self.assertManyRelationsEqual([ | ||
(func('seed'), self.unique_schema(), self.default_database), | ||
(func('view_2'), self.unique_schema(), self.alternative_database), | ||
|
@@ -101,9 +148,9 @@ def run_database_override(self): | |
self.use_default_project({ | ||
'seeds': {'database': self.alternative_database} | ||
}) | ||
self.run_dbt(['seed']) | ||
self.run_dbt_notstrict(['seed']) | ||
|
||
self.assertEqual(len(self.run_dbt(['run'])), 4) | ||
self.assertEqual(len(self.run_dbt_notstrict(['run'])), 4) | ||
self.assertManyRelationsEqual([ | ||
(func('seed'), self.unique_schema(), self.alternative_database), | ||
(func('view_2'), self.unique_schema(), self.alternative_database), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the most pleasant thing in the world, but I think it's a good and appropriate fix for this problem. Nice