Skip to content

Commit

Permalink
Test pr 418 (#419)
Browse files Browse the repository at this point in the history
* feat: Add temporary option to the create stage command.

* update changelog

* Update tests/test_create.py

Co-authored-by: Adam Ling <[email protected]>

---------

Co-authored-by: DanCardin <[email protected]>
Co-authored-by: Adam Ling <[email protected]>
  • Loading branch information
3 people authored Jun 6, 2023
1 parent c563913 commit c200f97
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Source code is also available at:

# Release Notes

- v1.4.8(TBD)

- Added opiton to create a temporary stage command.

- v1.4.7(Mar 22, 2023)

- Re-applied the application name of driver connection `SnowflakeConnection` to `SnowflakeSQLAlchemy`.
Expand Down
5 changes: 3 additions & 2 deletions src/snowflake/sqlalchemy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,12 @@ def visit_create_stage(self, create_stage, **kw):
"""
This visitor will create the SQL representation for a CREATE STAGE command.
"""
return "CREATE {}STAGE {}{} URL={}".format(
"OR REPLACE " if create_stage.replace_if_exists else "",
return "CREATE {or_replace}{temporary}STAGE {}{} URL={}".format(
create_stage.stage.namespace,
create_stage.stage.name,
repr(create_stage.container),
or_replace="OR REPLACE " if create_stage.replace_if_exists else "",
temporary="TEMPORARY " if create_stage.temporary else "",
)

def visit_create_file_format(self, file_format, **kw):
Expand Down
3 changes: 2 additions & 1 deletion src/snowflake/sqlalchemy/custom_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,10 @@ class CreateStage(DDLElement):

__visit_name__ = "create_stage"

def __init__(self, container, stage, replace_if_exists=False):
def __init__(self, container, stage, replace_if_exists=False, *, temporary=False):
super().__init__()
self.container = container
self.temporary = temporary
self.stage = stage
self.replace_if_exists = replace_if_exists

Expand Down
10 changes: 10 additions & 0 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def test_create_stage(sql_compiler):
)
assert actual == expected

create_stage = CreateStage(stage=stage, container=container, temporary=True)
# validate that the resulting SQL is as expected
actual = sql_compiler(create_stage)
expected = (
"CREATE TEMPORARY STAGE MY_DB.MY_SCHEMA.AZURE_STAGE "
"URL='azure://myaccount.blob.core.windows.net/my-container' "
"CREDENTIALS=(AZURE_SAS_TOKEN='saas_token')"
)
assert actual == expected


def test_create_csv_format(sql_compiler):
"""
Expand Down

0 comments on commit c200f97

Please sign in to comment.