diff --git a/core/dbt/artifacts/resources/v1/saved_query.py b/core/dbt/artifacts/resources/v1/saved_query.py index cc24d8fddf4..295b3aef45f 100644 --- a/core/dbt/artifacts/resources/v1/saved_query.py +++ b/core/dbt/artifacts/resources/v1/saved_query.py @@ -2,6 +2,9 @@ import time from dataclasses import dataclass, field + +from dbt_semantic_interfaces.implementations.semantic_model import NodeRelation + from dbt.artifacts.resources.base import GraphResource from dbt.artifacts.resources.v1.components import DependsOn, RefArgs from dbt.artifacts.resources.v1.semantic_layer_components import ( @@ -73,6 +76,7 @@ class SavedQueryConfig(BaseConfig): class SavedQueryMandatory(GraphResource): query_params: QueryParams exports: List[Export] + node_relation: Optional[NodeRelation] @dataclass diff --git a/core/dbt/artifacts/resources/v1/semantic_model.py b/core/dbt/artifacts/resources/v1/semantic_model.py index b219b2bdcc8..bacd1b41328 100644 --- a/core/dbt/artifacts/resources/v1/semantic_model.py +++ b/core/dbt/artifacts/resources/v1/semantic_model.py @@ -1,6 +1,9 @@ import time from dataclasses import dataclass, field + +from dbt_semantic_interfaces.implementations.semantic_model import NodeRelation + from dbt.artifacts.resources.base import GraphResource from dbt.artifacts.resources.v1.components import DependsOn, RefArgs from dbt_common.contracts.config.base import BaseConfig, CompareBehavior, MergeBehavior @@ -37,14 +40,6 @@ class Defaults(dbtClassMixin): agg_time_dimension: Optional[str] = None -@dataclass -class NodeRelation(dbtClassMixin): - alias: str - schema_name: str # TODO: Could this be called simply "schema" so we could reuse StateRelation? - database: Optional[str] = None - relation_name: Optional[str] = None - - # ==================================== # Dimension objects # Dimension protocols: https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/dbt_semantic_interfaces/protocols/dimension.py diff --git a/core/dbt/parser/manifest.py b/core/dbt/parser/manifest.py index 0dd3ec08423..ba6a7406a30 100644 --- a/core/dbt/parser/manifest.py +++ b/core/dbt/parser/manifest.py @@ -482,7 +482,6 @@ def load(self) -> Manifest: self.process_unit_tests(self.root_project.project_name) self.process_docs(self.root_project) self.process_metrics(self.root_project) - self.process_saved_queries(self.root_project) self.check_valid_group_config() self.check_valid_access_property() @@ -1104,6 +1103,11 @@ def process_refs(self, current_project: str, dependencies: Optional[Mapping[str, continue _process_refs(self.manifest, current_project, semantic_model, dependencies) self.update_semantic_model(semantic_model) + for saved_query in self.manifest.saved_queries.values(): + if saved_query.created_at < self.started_at: + continue + _process_refs(self.manifest, current_project, saved_query, dependencies) + self.update_saved_query(saved_query, current_project) # Takes references in 'metrics' array of nodes and exposures, finds the target # node, and updates 'depends_on.nodes' with the unique id @@ -1123,14 +1127,20 @@ def process_metrics(self, config: RuntimeConfig): continue _process_metrics_for_node(self.manifest, current_project, exposure) - def process_saved_queries(self, config: RuntimeConfig): + def update_saved_query(self, saved_query: SavedQuery, current_project: str) -> None: """Processes SavedQuery nodes to populate their `depends_on`.""" - current_project = config.project_name - for saved_query in self.manifest.saved_queries.values(): - # TODO: - # 1. process `where` of SavedQuery for `depends_on`s - # 2. process `group_by` of SavedQuery for `depends_on`` - _process_metrics_for_node(self.manifest, current_project, saved_query) + # TODO: + # 1. process `where` of SavedQuery for `depends_on`s + # 2. process `group_by` of SavedQuery for `depends_on`` + _process_metrics_for_node(self.manifest, current_project, saved_query) + if saved_query.depends_on_nodes[0]: + refd_node = self.manifest.nodes[saved_query.depends_on_nodes[0]] + saved_query.node_relation = NodeRelation( + relation_name=refd_node.relation_name, + alias=refd_node.alias, + schema_name=refd_node.schema, + database=refd_node.database, + ) def update_semantic_model(self, semantic_model) -> None: # This has to be done at the end of parsing because the referenced model