-
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
Fix table/schema quoting on drop, truncate, and rename (#983) #991
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0cf38bc
set quote policy on all cls.Relation.create() invocations
99a04e9
add tests for quoting
8e9a44e
Merge branch 'dev/lucretia-mott' into fix/drop-table-quoting
f2d1537
fix typo
18f3849
Merge branch 'dev/lucretia-mott' into fix/drop-table-quoting
7cbec9e
PR feedback
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import mock | ||
import unittest | ||
|
||
import dbt.flags as flags | ||
|
||
import dbt.adapters | ||
from dbt.adapters.snowflake import SnowflakeAdapter | ||
from dbt.exceptions import ValidationException | ||
from dbt.logger import GLOBAL_LOGGER as logger # noqa | ||
from snowflake import connector as snowflake_connector | ||
|
||
class TestSnowflakeAdapter(unittest.TestCase): | ||
def setUp(self): | ||
flags.STRICT_MODE = False | ||
|
||
self.profile = { | ||
'dbname': 'postgres', | ||
'user': 'root', | ||
'host': 'database', | ||
'pass': 'password', | ||
'port': 5432, | ||
'schema': 'public' | ||
} | ||
|
||
self.project = { | ||
'name': 'X', | ||
'version': '0.1', | ||
'profile': 'test', | ||
'project-root': '/tmp/dbt/does-not-exist', | ||
'quoting': { | ||
'identifier': False, | ||
'schema': True, | ||
} | ||
} | ||
|
||
self.handle = mock.MagicMock(spec=snowflake_connector.SnowflakeConnection) | ||
self.cursor = self.handle.cursor.return_value | ||
self.mock_execute = self.cursor.execute | ||
self.patcher = mock.patch('dbt.adapters.snowflake.impl.snowflake.connector.connect') | ||
self.snowflake = self.patcher.start() | ||
|
||
self.snowflake.return_value = self.handle | ||
conn = SnowflakeAdapter.get_connection(self.profile) | ||
|
||
def tearDown(self): | ||
# we want a unique self.handle every time. | ||
SnowflakeAdapter.cleanup_connections() | ||
self.patcher.stop() | ||
|
||
def test_quoting_on_drop_schema(self): | ||
SnowflakeAdapter.drop_schema( | ||
profile=self.profile, | ||
project_cfg=self.project, | ||
schema='test_schema' | ||
) | ||
|
||
self.mock_execute.assert_has_calls([ | ||
mock.call('drop schema if exists "test_schema" cascade', None) | ||
]) | ||
|
||
def test_quoting_on_drop(self): | ||
SnowflakeAdapter.drop( | ||
profile=self.profile, | ||
project_cfg=self.project, | ||
schema='test_schema', | ||
relation='test_table', | ||
relation_type='table' | ||
) | ||
self.mock_execute.assert_has_calls([ | ||
mock.call('drop table if exists "test_schema".test_table cascade', None) | ||
]) | ||
|
||
def test_quoting_on_truncate(self): | ||
SnowflakeAdapter.truncate( | ||
profile=self.profile, | ||
project_cfg=self.project, | ||
schema='test_schema', | ||
table='test_table' | ||
) | ||
self.mock_execute.assert_has_calls([ | ||
mock.call('truncate table "test_schema".test_table', None) | ||
]) | ||
|
||
def test_quoting_on_rename(self): | ||
SnowflakeAdapter.rename( | ||
profile=self.profile, | ||
project_cfg=self.project, | ||
schema='test_schema', | ||
from_name='table_a', | ||
to_name='table_b' | ||
) | ||
self.mock_execute.assert_has_calls([ | ||
mock.call('alter table "test_schema".table_a rename to table_b', None) | ||
]) |
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.
should this be
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.
Yes, thank you!
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.
do we need to account for
project
here too?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.
also, I'm pretty confused about
cls.DEFAULT_QUOTE
. Why would we use that instead of the default quote policy on a given Relation class?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.
I didn't really realize how that worked, I've moved it to use that instead.