From ff10f1960afd17ac066b18860363b5dc06b066b2 Mon Sep 17 00:00:00 2001 From: Tsung-Ju Lii Date: Thu, 31 Oct 2024 22:24:49 +0800 Subject: [PATCH] [sc-29648] Use `init_virtual_view` to get or create the source model in `depends_on` --- metaphor/dbt/cloud/parser/common.py | 19 ++++++++++++++++--- pyproject.toml | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/metaphor/dbt/cloud/parser/common.py b/metaphor/dbt/cloud/parser/common.py index 3652a7b6..d39ae495 100644 --- a/metaphor/dbt/cloud/parser/common.py +++ b/metaphor/dbt/cloud/parser/common.py @@ -1,9 +1,15 @@ import json -from typing import Dict, List, Union +from typing import Callable, Dict, List, Union from metaphor.common.entity_id import EntityId from metaphor.common.utils import dedup_lists, unique_list -from metaphor.dbt.util import build_system_tags, get_virtual_view_id +from metaphor.dbt.util import ( + build_system_tags, + get_model_name_from_unique_id, + get_snapshot_name_from_unique_id, + get_virtual_view_id, + init_virtual_view, +) from metaphor.models.metadata_change_event import ( Dataset, DbtMacro, @@ -35,10 +41,17 @@ def parse_depends_on( or None ) + def get_source_model_name(n: str) -> Callable[[str], str]: + if n.startswith("model."): + return get_model_name_from_unique_id + if n.startswith("snapshot."): + return get_snapshot_name_from_unique_id + assert False + target.source_models = ( unique_list( [ - get_virtual_view_id(virtual_views[n].logical_id) # type: ignore + get_virtual_view_id(init_virtual_view(virtual_views, n, get_source_model_name).logical_id) # type: ignore for n in depends_on if n.startswith("model.") or n.startswith("snapshot.") ] diff --git a/pyproject.toml b/pyproject.toml index c55dfb0d..5f4eafe5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "metaphor-connectors" -version = "0.14.140" +version = "0.14.141" 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 "]