Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
littleK0i committed Apr 19, 2024
1 parent e494261 commit b0e28e0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
1 change: 1 addition & 0 deletions snowddl/blueprint/ident.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def database_full_name(self):
def schema_full_name(self):
return SchemaIdent(self.env_prefix, self.database, self.schema)


class SchemaObjectIdentWithArgs(SchemaObjectIdent):
def __init__(self, env_prefix, database, schema, name, data_types: List[BaseDataType]):
super().__init__(env_prefix, database, schema, name)
Expand Down
10 changes: 6 additions & 4 deletions snowddl/cache/intention_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def check_parent_drop_intention(self, object_type: ObjectType, object_full_name:
schema_object_name = ".".join(object_full_name_parts[:3])

# All schemas and schema objects are implicitly dropped by DATABASE
if issubclass(blueprint_cls, (SchemaBlueprint, SchemaObjectBlueprint)) and (database_name in self.drop_intention[ObjectType.DATABASE]):
if issubclass(blueprint_cls, (SchemaBlueprint, SchemaObjectBlueprint)) and (
database_name in self.drop_intention[ObjectType.DATABASE]
):
return True

# All schema objects are implicitly dropped by SCHEMA
Expand All @@ -50,9 +52,9 @@ def check_parent_drop_intention(self, object_type: ObjectType, object_full_name:

# All table constraints are implicitly dropped by various TABLE types which support constraints
if issubclass(blueprint_cls, (ForeignKeyBlueprint, PrimaryKeyBlueprint, UniqueKeyBlueprint)) and (
schema_object_name in self.drop_intention[ObjectType.TABLE] or
schema_object_name in self.drop_intention[ObjectType.EXTERNAL_TABLE] or
schema_object_name in self.drop_intention[ObjectType.HYBRID_TABLE]
schema_object_name in self.drop_intention[ObjectType.TABLE]
or schema_object_name in self.drop_intention[ObjectType.EXTERNAL_TABLE]
or schema_object_name in self.drop_intention[ObjectType.HYBRID_TABLE]
):
return True

Expand Down
13 changes: 8 additions & 5 deletions snowddl/parser/hybrid_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,14 @@ def process_table(self, f: ParsedFile):
unique_keys = [[Ident(c) for c in columns] for columns in f.params.get("unique_keys")]

if f.params.get("foreign_keys"):
foreign_keys = [ForeignKeyReference(
columns=[Ident(c) for c in fk["columns"]],
ref_table_name=build_schema_object_ident(self.env_prefix, fk["ref_table"], f.database, f.schema),
ref_columns=[Ident(c) for c in fk["ref_columns"]],
) for fk in f.params.get("foreign_keys")]
foreign_keys = [
ForeignKeyReference(
columns=[Ident(c) for c in fk["columns"]],
ref_table_name=build_schema_object_ident(self.env_prefix, fk["ref_table"], f.database, f.schema),
ref_columns=[Ident(c) for c in fk["ref_columns"]],
)
for fk in f.params.get("foreign_keys")
]

depends_on = set(fk.ref_table_name for fk in foreign_keys)

Expand Down
11 changes: 10 additions & 1 deletion snowddl/resolver/hybrid_table.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from re import compile

from snowddl.blueprint import Ident, DataType, HybridTableBlueprint, SchemaObjectIdent, TableColumn, PrimaryKeyBlueprint, UniqueKeyBlueprint, ForeignKeyBlueprint
from snowddl.blueprint import (
Ident,
DataType,
HybridTableBlueprint,
SchemaObjectIdent,
TableColumn,
PrimaryKeyBlueprint,
UniqueKeyBlueprint,
ForeignKeyBlueprint,
)
from snowddl.resolver.abc_schema_object_resolver import AbstractSchemaObjectResolver, ResolveResult, ObjectType

collate_type_syntax_re = compile(r"^(.*) COLLATE \'(.*)\'$")
Expand Down
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def show_indexes(self, database, schema, name):
},
)

return {r['name']: r for r in cur}
return {r["name"]: r for r in cur}

def is_edition_enterprise(self):
return self.edition >= Edition.ENTERPRISE
Expand Down
12 changes: 8 additions & 4 deletions test/hybrid_table/ht001.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def test_step1(helper):

assert 2 == len(foreign_keys)
assert {"columns": ["NUM2"], "ref_table": f"{helper.env_prefix}DB1.SC1.HT001_HT2", "ref_columns": ["ID"]} in foreign_keys
assert {"columns": ["VAR1", "VAR2"], "ref_table": f"{helper.env_prefix}DB1.SC1.HT001_HT2", "ref_columns": ["FIRST_NAME", "LAST_NAME"]} in foreign_keys
assert {
"columns": ["VAR1", "VAR2"],
"ref_table": f"{helper.env_prefix}DB1.SC1.HT001_HT2",
"ref_columns": ["FIRST_NAME", "LAST_NAME"],
} in foreign_keys

assert "SYS_INDEX_HT001_HT1_PRIMARY" in indexes
assert "SYS_INDEX_HT001_HT1_UNIQUE_NUM2" in indexes
Expand All @@ -37,9 +41,9 @@ def test_step2(helper):
# TODO: uncomment these checks when Snowflake fixes foreign keys for Hybrid Tables
# As of 19 Apr 2024, it is no longer possible to add foreign key to existing Hybrid Table

#assert 2 == len(foreign_keys)
#assert {"columns": ["NUM2"], "ref_table": f"{helper.env_prefix}DB1.SC1.HT001_HT2", "ref_columns": ["ID"]} in foreign_keys
#assert {"columns": ["VAR1", "VAR2"], "ref_table": f"{helper.env_prefix}DB1.SC1.HT001_HT2", "ref_columns": ["FIRST_NAME", "LAST_NAME"]} in foreign_keys
# assert 2 == len(foreign_keys)
# assert {"columns": ["NUM2"], "ref_table": f"{helper.env_prefix}DB1.SC1.HT001_HT2", "ref_columns": ["ID"]} in foreign_keys
# assert {"columns": ["VAR1", "VAR2"], "ref_table": f"{helper.env_prefix}DB1.SC1.HT001_HT2", "ref_columns": ["FIRST_NAME", "LAST_NAME"]} in foreign_keys


def test_step3(helper):
Expand Down

0 comments on commit b0e28e0

Please sign in to comment.