Skip to content

Commit

Permalink
Change hierarchy systemTags type (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
usefulalgorithm authored Nov 16, 2023
1 parent 668f485 commit 50fb191
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
8 changes: 6 additions & 2 deletions metaphor/snowflake/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
SourceInfo,
SQLSchema,
SystemTag,
SystemTags,
SystemTagSource,
)
from metaphor.snowflake import auth
Expand Down Expand Up @@ -409,8 +410,11 @@ def _add_system_tag(
logical_id = HierarchyLogicalID(path=path)

self._hierarchies.setdefault(
hierarchy_key, Hierarchy(logical_id=logical_id, system_tags=[])
).system_tags.append(
hierarchy_key,
Hierarchy(
logical_id=logical_id, system_tags=SystemTags(tags=[])
), # SystemTags.tags should never be empty
).system_tags.tags.append(
SystemTag(
key=tag_key,
system_tag_source=SystemTagSource.SNOWFLAKE,
Expand Down
28 changes: 14 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "metaphor-connectors"
version = "0.13.48"
version = "0.13.49"
license = "Apache-2.0"
description = "A collection of Python-based 'connectors' that extract metadata from various sources to ingest into the Metaphor app."
authors = ["Metaphor <[email protected]>"]
Expand Down Expand Up @@ -30,7 +30,7 @@ google-cloud-logging = { version = "^3.5.0", optional = true }
jsonschema = "^4.18.6"
lkml = { version = "^1.3.1", optional = true }
looker-sdk = { version = "^23.6.0", optional = true }
metaphor-models = "0.30.3"
metaphor-models = "0.30.5"
msal = { version = "^1.20.0", optional = true }
msgraph-beta-sdk = { version = "1.0.0", optional = true }
pycarlo = { version = "^0.8.1", optional = true }
Expand Down
35 changes: 23 additions & 12 deletions tests/snowflake/test_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
QueriedDataset,
SchemaField,
SystemTag,
SystemTags,
SystemTagSource,
)
from metaphor.snowflake.config import SnowflakeQueryLogConfig, SnowflakeRunConfig
Expand Down Expand Up @@ -271,25 +272,35 @@ def test_fetch_hierarchy_system_tags(mock_connect: MagicMock):
path=[DataPlatform.SNOWFLAKE.value, table_name]
)
assert db_hierarchy.system_tags is not None
assert db_hierarchy.system_tags == [
SystemTag(key="foo", system_tag_source=SystemTagSource.SNOWFLAKE, value="bar"),
SystemTag(
key="grault", system_tag_source=SystemTagSource.SNOWFLAKE, value="garply"
),
]
assert db_hierarchy.system_tags == SystemTags(
tags=[
SystemTag(
key="foo", system_tag_source=SystemTagSource.SNOWFLAKE, value="bar"
),
SystemTag(
key="grault",
system_tag_source=SystemTagSource.SNOWFLAKE,
value="garply",
),
]
)
schema_hierarchy = extractor._hierarchies[
dataset_normalized_name(database, table_name)
]
assert schema_hierarchy.logical_id == HierarchyLogicalID(
path=[DataPlatform.SNOWFLAKE.value, database, table_name]
)
assert schema_hierarchy.system_tags is not None
assert schema_hierarchy.system_tags == [
SystemTag(key="baz", system_tag_source=SystemTagSource.SNOWFLAKE, value="qux"),
SystemTag(
key="quux", system_tag_source=SystemTagSource.SNOWFLAKE, value="corge"
),
]
assert schema_hierarchy.system_tags == SystemTags(
tags=[
SystemTag(
key="baz", system_tag_source=SystemTagSource.SNOWFLAKE, value="qux"
),
SystemTag(
key="quux", system_tag_source=SystemTagSource.SNOWFLAKE, value="corge"
),
]
)


@patch("metaphor.snowflake.auth.connect")
Expand Down

0 comments on commit 50fb191

Please sign in to comment.