Skip to content

Commit

Permalink
Update logic for skipping new fancy table types; Added more explicit …
Browse files Browse the repository at this point in the history
…permissions for dynamic tables; Update metadata handling for optional arguments in functions and procedures
  • Loading branch information
littleK0i committed Mar 8, 2024
1 parent 1c278b4 commit 8847918
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 23 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [0.23.2] - 2024-03-08

- Skipped all new fancy table types while working on normal `TABLE` in resolver, converter and during cloning.
- Added explicit `MONITOR`, `OPERATE` and `SELECT` privileges for `DYNAMIC_TABLE` for schema owner role.
- Added explicit `SELECT` privilege for `DYNAMIC_TABLE` for schema read role.
- Updated handling of metadata for optional arguments in `FUNCTION` and `PROCEDURE`. Snowflake replaced brackets-syntax `[, NUMBER]` with more traditional `, DEFAULT NUMBER`.

You may have to run SnowDDL with flag `--refresh-future-grants` to apply new privileges to existing dynamic tables.

## [0.23.1] - 2024-01-17

- Added `owner_integration_usage` parameter for `SCHEMA`. It grants usage privilege to schema owner role on integrations pre-configured outside SnowDDL.
Expand Down
8 changes: 2 additions & 6 deletions snowddl/converter/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ def get_existing_objects_in_schema(self, schema: dict):
)

for r in cur:
# Skip external tables
if r["is_external"] == "Y":
continue

# Skip event tables
if r["is_event"] == "Y":
# Skip other table types
if r["is_external"] == "Y" or r["is_event"] == "Y" or r["is_hybrid"] == "Y" or r["is_iceberg"] == "Y":
continue

full_name = f"{r['database_name']}.{r['schema_name']}.{r['name']}"
Expand Down
1 change: 1 addition & 0 deletions snowddl/resolver/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def compare_dynamic_param_value(bp_value: Union[bool, int, float, str], existing


def dtypes_from_arguments(arguments: str) -> str:
arguments = arguments.replace("DEFAULT ", "")
arguments = arguments.translate(str.maketrans("", "", "[] "))

start_dtypes_idx = arguments.index("(")
Expand Down
8 changes: 2 additions & 6 deletions snowddl/resolver/clone_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,8 @@ def get_tables_for_clone(self, schema):
)

for r in cur:
# Skip external tables
if r["is_external"] == "Y":
continue

# Skip event tables
if r["is_event"] == "Y":
# Skip other table types
if r["is_external"] == "Y" or r["is_event"] == "Y" or r["is_hybrid"] == "Y" or r["is_iceberg"] == "Y":
continue

tables_for_clone[f"{self.config.env_prefix}{r['database_name']}.{r['schema_name']}.{r['name']}"] = {
Expand Down
2 changes: 2 additions & 0 deletions snowddl/resolver/schema_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def get_blueprint_owner_role(self, schema_bp: SchemaBlueprint):
)

privileges_map = {
ObjectType.DYNAMIC_TABLE: ["MONITOR", "OPERATE", "SELECT"],
ObjectType.STAGE: ["READ", "WRITE", "USAGE"],
}

Expand Down Expand Up @@ -132,6 +133,7 @@ def get_blueprint_read_role(self, schema_bp: SchemaBlueprint):
)

privileges_map = {
ObjectType.DYNAMIC_TABLE: ["SELECT"],
ObjectType.EXTERNAL_TABLE: ["SELECT", "REFERENCES"],
ObjectType.FILE_FORMAT: ["USAGE"],
ObjectType.FUNCTION: ["USAGE"],
Expand Down
8 changes: 2 additions & 6 deletions snowddl/resolver/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ def get_existing_objects_in_schema(self, schema: dict):
)

for r in cur:
# Skip external tables
if r["is_external"] == "Y":
continue

# Skip event tables
if r["is_event"] == "Y":
# Skip other table types
if r["is_external"] == "Y" or r["is_event"] == "Y" or r["is_hybrid"] == "Y" or r["is_iceberg"] == "Y":
continue

full_name = f"{r['database_name']}.{r['schema_name']}.{r['name']}"
Expand Down
2 changes: 1 addition & 1 deletion snowddl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.23.1"
__version__ = "0.23.2"
1 change: 1 addition & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def is_edition_business_critical(self):
return self.edition >= Edition.BUSINESS_CRITICAL

def dtypes_from_arguments(self, arguments):
arguments = arguments.replace("DEFAULT ", "")
arguments = arguments.translate(str.maketrans("", "", "[] "))

start_dtypes_idx = arguments.index("(")
Expand Down
4 changes: 2 additions & 2 deletions test/function/fn008.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_step1(helper):
)

assert function_desc["language"] == "SQL"
assert "[" in function_show["arguments"]
assert "DEFAULT" in function_show["arguments"]


def test_step2(helper):
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_step2(helper):
)

assert function_desc["language"] == "SQL"
assert "[" in function_show["arguments"]
assert "DEFAULT" in function_show["arguments"]


def test_step3(helper):
Expand Down
4 changes: 2 additions & 2 deletions test/procedure/pr004.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_step1(helper):
"ARR ARRAY)"
)

assert "[" in procedure_show["arguments"]
assert "DEFAULT" in procedure_show["arguments"]


def test_step2(helper):
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_step2(helper):
"ARR ARRAY)"
)

assert "[" in procedure_show["arguments"]
assert "DEFAULT" in procedure_show["arguments"]


def test_step3(helper):
Expand Down

0 comments on commit 8847918

Please sign in to comment.