Skip to content

Commit

Permalink
Add display in catalogue tag to cadet dbs (#153)
Browse files Browse the repository at this point in the history
* pick up `dc_display_in_catalogue` tag at point of container creation

* cos it is just the key

* remove method i didnt use

* remove conditional as per mat suggestion
  • Loading branch information
LavMatt authored Jun 17, 2024
1 parent 7821e1c commit f79dc33
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions ingestion/create_cadet_databases_source/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def get_workunits(self) -> Iterable[MetadataWorkUnit]:
yield wu

# Create database entities and assign them to their domains
databases_with_domains = self._get_databases_with_domains(manifest)
databases_with_domains, display_tags = (
self._get_databases_with_domains_and_display_tags(manifest)
)
sub_types = [DatasetContainerSubTypes.DATABASE]
last_modified = int(datetime.now().timestamp())
for database, domain in databases_with_domains:
Expand All @@ -56,6 +58,8 @@ def get_workunits(self) -> Iterable[MetadataWorkUnit]:
backcompat_env_as_instance=True,
)
domain_urn = mce_builder.make_domain_urn(domain=domain)
display_tag = display_tags.get(database)

logging.info(f"Creating container {database=} with {domain=}")
yield from mcp_builder.gen_containers(
container_key=database_container_key,
Expand All @@ -66,7 +70,7 @@ def get_workunits(self) -> Iterable[MetadataWorkUnit]:
description=None,
created=None,
last_modified=last_modified,
tags=None,
tags=display_tag,
owner_urn=None,
qualified_name=None,
extra_properties=None,
Expand All @@ -80,20 +84,35 @@ def _get_domains(self, manifest) -> set[str]:
if manifest["nodes"][node]["resource_type"] == "model"
)

def _get_databases_with_domains(self, manifest) -> list[tuple[str, str]]:
def _get_databases_with_domains_and_display_tags(
self, manifest
) -> tuple[set[tuple[str, str]], dict]:
"""
These mappings will only work with tables named {database}__{table}
like create a derived table
like create a derived table.
returns a set of databases with associated domain and a dict for
display tags, where key is database and value is dc_display_in_catalogue
if any model is to be displayed
"""
mappings = set()
tags = {}
for node in manifest["nodes"]:
if manifest["nodes"][node]["resource_type"] == "model":
fqn = manifest["nodes"][node]["fqn"]
if validate_fqn(fqn):
database = fqn[-1].split("__")[0]
domain = fqn[1]
tag = (
"dc_display_in_catalogue"
if "dc_display_in_catalogue" in manifest["nodes"][node]["tags"]
else None
)
mappings.add((database, domain))
return mappings
if tag is not None:
tags[database] = [tag]

return mappings, tags

def _make_domain(self, domain_name) -> MetadataChangeProposalWrapper:
domain_urn = mce_builder.make_domain_urn(domain=domain_name)
Expand Down

0 comments on commit f79dc33

Please sign in to comment.