Skip to content

Commit

Permalink
support relationships to sources
Browse files Browse the repository at this point in the history
  • Loading branch information
gouline committed Nov 1, 2024
1 parent 160e2fb commit ed26764
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions dbtmetabase/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,22 @@ def _read_relationships(
continue

depends_on_id = depends_on_nodes[0]
depends_on_group = Group.from_unique_id(depends_on_id)
if not depends_on_group:
_logger.debug("Unknown group dependency '%s'", depends_on_id)
continue

fk_target_model = manifest[group].get(depends_on_id, {})
fk_target_table = fk_target_model.get(
"alias",
fk_target_model.get("identifier", fk_target_model.get("name")),
fk_target_model = manifest[depends_on_group].get(depends_on_id, {})
fk_target_table = (
fk_target_model.get("alias")
or fk_target_model.get("identifier")
or fk_target_model.get("name")
)
if not fk_target_table:
_logger.debug("Cannot resolve dependency for '%s'", depends_on_id)
continue

fk_target_schema = manifest[group][depends_on_id].get(
"schema", DEFAULT_SCHEMA
)
fk_target_schema = fk_target_model.get("schema", DEFAULT_SCHEMA)
fk_target_table = f"{fk_target_schema}.{fk_target_table}"
fk_target_field = child["test_metadata"]["kwargs"]["field"].strip('"')

Expand Down Expand Up @@ -341,6 +344,14 @@ class Group(str, Enum):
nodes = "nodes"
sources = "sources"

@staticmethod
def from_unique_id(unique_id: str) -> Optional[Group]:
if prefix := unique_id.split(".")[0] == "source":
return Group.sources
elif prefix == "model":
return Group.nodes
return None


@dc.dataclass
class Column:
Expand Down

0 comments on commit ed26764

Please sign in to comment.