Skip to content

Commit

Permalink
tag tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teej committed Nov 8, 2024
1 parent 86a28ca commit 4d11268
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 43 deletions.
8 changes: 8 additions & 0 deletions tests/integration/data_provider/test_list_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ def test_list_resource(cursor, list_resources_database, resource, marked_for_cle
list_resources = data_provider.list_resource(cursor, resource_label_for_type(resource.resource_type))
assert len(list_resources) > 0
assert resource.fqn in list_resources


@pytest.mark.enterprise
def test_list_tag_references(cursor):
data_provider.fetch_session.cache_clear()
reset_cache()
tag_references = data_provider.list_tag_references(cursor)
assert len(tag_references) > 0

Check warning on line 98 in tests/integration/data_provider/test_list_resource.py

View check run for this annotation

Codecov / codecov/patch

tests/integration/data_provider/test_list_resource.py#L95-L98

Added lines #L95 - L98 were not covered by tests
79 changes: 36 additions & 43 deletions titan/data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2613,50 +2613,43 @@ def list_tables(session: SnowflakeConnection) -> list[FQN]:
return tables


# def list_tag_references(session: SnowflakeConnection) -> list[FQN]:
# try:
# show_result = execute(session, "SHOW TAGS IN ACCOUNT")
# tag_references: list[FQN] = []
# for tag in show_result:
# if tag["database_name"] in SYSTEM_DATABASES or tag["schema_name"] == "INFORMATION_SCHEMA":
# continue

# tag_refs = execute(
# session,
# f"""
# SELECT *
# FROM table(snowflake.account_usage.tag_references_with_lineage(
# '{tag['database_name']}.{tag['schema_name']}.{tag['name']}'
# ))
# """,
# )

# for ref in tag_refs:
# if ref["OBJECT_DELETED"] is not None:
# continue
# print(ref)
# # raise
# return tag_references

# # tags.append(
# # FQN(
# # database=resource_name_from_snowflake_metadata(row["database_name"]),
# # schema=resource_name_from_snowflake_metadata(tag["schema_name"]),
# # name=resource_name_from_snowflake_metadata(tag["name"]),
# # )
# # )
# # return tags
# except ProgrammingError as err:
# if err.errno == UNSUPPORTED_FEATURE:
# return []
# else:
# raise
def list_tag_references(session: SnowflakeConnection) -> list[FQN]:
try:
show_result = execute(session, "SHOW TAGS IN ACCOUNT")
tag_references: list[FQN] = []
for tag in show_result:
if tag["database_name"] in SYSTEM_DATABASES or tag["schema_name"] == "INFORMATION_SCHEMA":
continue

# tag_map = {}
# for tag_ref in tag_refs:
# tag_name = f"{tag_ref['TAG_DATABASE']}.{tag_ref['TAG_SCHEMA']}.{tag_ref['TAG_NAME']}"
# tag_map[tag_name] = tag_ref["TAG_VALUE"]
# return tag_map
tag_refs = execute(
session,
f"""
SELECT *
FROM table(snowflake.account_usage.tag_references_with_lineage(
'{tag['database_name']}.{tag['schema_name']}.{tag['name']}'
))
""",
)

for ref in tag_refs:
if ref["OBJECT_DELETED"] is not None:
continue

tag_references.append(

Check warning on line 2638 in titan/data_provider.py

View check run for this annotation

Codecov / codecov/patch

titan/data_provider.py#L2638

Added line #L2638 was not covered by tests
FQN(
database=resource_name_from_snowflake_metadata(ref["TAG_DATABASE"]),
schema=resource_name_from_snowflake_metadata(ref["TAG_SCHEMA"]),
name=resource_name_from_snowflake_metadata(ref["TAG_NAME"]),
)
)

return tag_references

except ProgrammingError as err:
if err.errno == UNSUPPORTED_FEATURE:
return []
else:
raise


def list_tags(session: SnowflakeConnection) -> list[FQN]:
Expand Down
6 changes: 6 additions & 0 deletions tools/test_account_configs/business_critical.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ grants:
- GRANT APPLY ROW ACCESS POLICY ON ACCOUNT TO ROLE EVERY_PRIVILEGE
- GRANT APPLY TAG ON ACCOUNT TO ROLE EVERY_PRIVILEGE

schemas:
- name: tagged_schema
database: static_database
tags:
static_database.public.static_tag: static_tag_value

tags:
- name: static_tag
database: static_database
Expand Down
6 changes: 6 additions & 0 deletions tools/test_account_configs/enterprise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ grants:
- GRANT APPLY ROW ACCESS POLICY ON ACCOUNT TO ROLE EVERY_PRIVILEGE
- GRANT APPLY TAG ON ACCOUNT TO ROLE EVERY_PRIVILEGE

schemas:
- name: tagged_schema
database: static_database
tags:
static_database.public.static_tag: static_tag_value

tags:
- name: static_tag
database: static_database
Expand Down

0 comments on commit 4d11268

Please sign in to comment.