Skip to content

Commit

Permalink
Fix issue with CLASS identifiers and unknown resources (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: TJ Murphy <[email protected]>
  • Loading branch information
teej and teej authored Jan 31, 2024
1 parent 5ed41c5 commit 46a78c1
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bp.apply(session, plan)
|-----------------------------------------|----------------|----------------|----------------|
| Plan and Execute Changes ||||
| Declarative Configuration ||||
| Python-Based Definitions || ||
| Python-Based Definitions || w/ CDKTF ||
| SQL Support ||||
| Multi-Role Support ||| N/A |
| No State File Dependency ||||
Expand Down
2 changes: 1 addition & 1 deletion scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RETURNS OBJECT NOT NULL
LANGUAGE PYTHON
RUNTIME_VERSION = '3.9'
PACKAGES = ('snowflake-snowpark-python', 'inflection', 'pyparsing')
IMPORTS = ('@titan_aws/releases/titan-0.1.2.zip')
IMPORTS = ('@titan_aws/releases/titan-0.1.3.zip')
HANDLER = 'titan.spi.install'
EXECUTE AS CALLER
CALL install()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="titan",
version="0.1.2",
version="0.1.3",
description="Snowflake infrastructure as code",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
Expand Down
1 change: 1 addition & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
('"db".schema."tbl"', ['"db"', "schema", '"tbl"']),
('"db"."schema".tbl', ['"db"', '"schema"', "tbl"]),
('db."this.is:schema".tbl', ["db", '"this.is:schema"', "tbl"]),
("TITAN_CLASS_TEST.PUBLIC.BASIC_MODEL.USER", ["TITAN_CLASS_TEST", "PUBLIC", "BASIC_MODEL", "USER"]),
]


Expand Down
2 changes: 1 addition & 1 deletion titan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Warehouse",
]

__version__ = "0.1.2"
__version__ = "0.1.3"

LOGO = r"""
__ _ __
Expand Down
6 changes: 5 additions & 1 deletion titan/data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,11 @@ def fetch_role_grants(session, role: str):
priv_map = defaultdict(list)

for row in show_result:
urn = _urn_from_grant(row, session_ctx)
try:
urn = _urn_from_grant(row, session_ctx)
except ValueError:
# Grant for a Snowflake resource type that Titan doesn't support yet
continue
priv_map[str(urn)].append(
{
"priv": row["privilege"],
Expand Down
12 changes: 11 additions & 1 deletion titan/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

Identifier = pp.Word(pp.alphanums + "_", pp.alphanums + "_$") | pp.dbl_quoted_string
FullyQualifiedIdentifier = (
pp.delimited_list(Identifier, delim=".", min=3, max=3)
pp.delimited_list(Identifier, delim=".", min=4, max=4)
^ pp.delimited_list(Identifier, delim=".", min=3, max=3)
^ pp.delimited_list(Identifier, delim=".", min=2, max=2)
^ Identifier
)
Expand Down Expand Up @@ -627,6 +628,15 @@ def parse_identifier(identifier: str, is_db_scoped=False) -> FQN:
params=params,
arg_types=arg_types,
)
elif len(name_parts) == 4:
params["entity"] = name_parts[3]
return FQN(
database=name_parts[0],
schema=name_parts[1],
name=name_parts[2],
params=params,
arg_types=arg_types,
)
raise Exception(f"Failed to parse identifier: {identifier}")


Expand Down

0 comments on commit 46a78c1

Please sign in to comment.