-
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
97a6a51
Quote databases when we list them
d515903
make PostgresAdapter.verify_database handle names that resolve to the…
fc4fc57
add a pretty janky data test to expose quoting issues
3188aea
More tests
8b58b20
add quote policy to Relation.create calls
2834f2d
update test.env.sample
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test/integration/001_simple_copy_test/tests/get_relation_quoting.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}' |
6 changes: 6 additions & 0 deletions
6
test/integration/040_override_database_test/models/view_1.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{{ | ||
config(database=var('alternate_db')) | ||
}} | ||
|
||
select * from {{ ref('seed') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:/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), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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