Skip to content

Commit

Permalink
CT-2719: Rename the semantic_nodes collection on the manifest to sema…
Browse files Browse the repository at this point in the history
…ntic_models
  • Loading branch information
peterallenwebb committed Jun 22, 2023
1 parent 6d7b329 commit e771ff5
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions core/dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ def link_node(self, node: GraphMemberNode, manifest: Manifest):
def link_graph(self, manifest: Manifest):
for source in manifest.sources.values():
self.add_node(source.unique_id)
for semantic_node in manifest.semantic_nodes.values():
self.add_node(semantic_node.unique_id)
for semantic_model in manifest.semantic_models.values():
self.add_node(semantic_model.unique_id)

for node in manifest.nodes.values():
self.link_node(node, manifest)
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class SchemaSourceFile(BaseSourceFile):
groups: List[str] = field(default_factory=list)
# node patches contain models, seeds, snapshots, analyses
ndp: List[str] = field(default_factory=list)
semantic_nodes: List[str] = field(default_factory=list)
semantic_models: List[str] = field(default_factory=list)
# any macro patches in this file by macro unique_id.
mcp: Dict[str, str] = field(default_factory=dict)
# any source patches in this file. The entries are package, name pairs
Expand Down
30 changes: 15 additions & 15 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ class Manifest(MacroMethods, DataClassMessagePackMixin, dbtClassMixin):
disabled: MutableMapping[str, List[GraphMemberNode]] = field(default_factory=dict)
env_vars: MutableMapping[str, str] = field(default_factory=dict)
publications: MutableMapping[str, PublicationConfig] = field(default_factory=dict)
semantic_nodes: MutableMapping[str, SemanticModel] = field(default_factory=dict)
semantic_models: MutableMapping[str, SemanticModel] = field(default_factory=dict)

_doc_lookup: Optional[DocLookup] = field(
default=None, metadata={"serialize": lambda x: None, "deserialize": lambda x: None}
Expand Down Expand Up @@ -753,8 +753,8 @@ def build_flat_graph(self):
"metrics": {k: v.to_dict(omit_none=False) for k, v in self.metrics.items()},
"nodes": {k: v.to_dict(omit_none=False) for k, v in self.nodes.items()},
"sources": {k: v.to_dict(omit_none=False) for k, v in self.sources.items()},
"semantic_nodes": {
k: v.to_dict(omit_none=False) for k, v in self.semantic_nodes.items()
"semantic_models": {
k: v.to_dict(omit_none=False) for k, v in self.semantic_models.items()
},
}

Expand Down Expand Up @@ -816,7 +816,7 @@ def get_resource_fqns(self) -> Mapping[str, PathSet]:
self.nodes.values(),
self.sources.values(),
self.metrics.values(),
self.semantic_nodes.values(),
self.semantic_models.values(),
)
for resource in all_resources:
resource_type_plural = resource.resource_type.pluralize()
Expand Down Expand Up @@ -852,7 +852,7 @@ def deepcopy(self):
files={k: _deepcopy(v) for k, v in self.files.items()},
state_check=_deepcopy(self.state_check),
publications={k: _deepcopy(v) for k, v in self.publications.items()},
semantic_nodes={k: _deepcopy(v) for k, v in self.semantic_nodes.items()},
semantic_models={k: _deepcopy(v) for k, v in self.semantic_models.items()},
)
copy.build_flat_graph()
return copy
Expand All @@ -864,7 +864,7 @@ def build_parent_and_child_maps(self):
self.sources.values(),
self.exposures.values(),
self.metrics.values(),
self.semantic_nodes.values(),
self.semantic_models.values(),
)
)
forward_edges, backward_edges = build_node_edges(edge_members)
Expand Down Expand Up @@ -911,7 +911,7 @@ def writable_manifest(self) -> "WritableManifest":
child_map=self.child_map,
parent_map=self.parent_map,
group_map=self.group_map,
semantic_nodes=self.semantic_nodes,
semantic_models=self.semantic_models,
)

def write(self, path):
Expand All @@ -928,8 +928,8 @@ def expect(self, unique_id: str) -> GraphMemberNode:
return self.exposures[unique_id]
elif unique_id in self.metrics:
return self.metrics[unique_id]
elif unique_id in self.semantic_nodes:
return self.semantic_nodes[unique_id]
elif unique_id in self.semantic_models:
return self.semantic_models[unique_id]
else:
# something terrible has happened
raise dbt.exceptions.DbtInternalError(
Expand Down Expand Up @@ -988,7 +988,7 @@ def analysis_lookup(self) -> AnalysisLookup:
def pydantic_semantic_manifest(self) -> PydanticSemanticManifest:
pydantic_semantic_manifest = PydanticSemanticManifest(metrics=[], semantic_models=[])

for semantic_model in self.semantic_nodes.values():
for semantic_model in self.semantic_models.values():
pydantic_semantic_manifest.semantic_models.append(
PydanticSemanticModel.parse_obj(semantic_model.to_dict())
)
Expand Down Expand Up @@ -1267,9 +1267,9 @@ def add_doc(self, source_file: SourceFile, doc: Documentation):
source_file.docs.append(doc.unique_id)

def add_semantic_model(self, source_file: SchemaSourceFile, semantic_model: SemanticModel):
_check_duplicates(semantic_model, self.semantic_nodes)
self.semantic_nodes[semantic_model.unique_id] = semantic_model
source_file.semantic_nodes.append(semantic_model.unique_id)
_check_duplicates(semantic_model, self.semantic_models)
self.semantic_models[semantic_model.unique_id] = semantic_model
source_file.semantic_models.append(semantic_model.unique_id)

# end of methods formerly in ParseResult

Expand Down Expand Up @@ -1298,7 +1298,7 @@ def __reduce_ex__(self, protocol):
self.disabled,
self.env_vars,
self.publications,
self.semantic_nodes,
self.semantic_models,
self._doc_lookup,
self._source_lookup,
self._ref_lookup,
Expand Down Expand Up @@ -1368,7 +1368,7 @@ class WritableManifest(ArtifactMixin):
description="A mapping from group names to their nodes",
)
)
semantic_nodes: Mapping[UniqueID, SemanticModel] = field(
semantic_models: Mapping[UniqueID, SemanticModel] = field(
metadata=dict(description=("The semantic models defined in the dbt project"))
)
metadata: ManifestMetadata = field(
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/contracts/graph/manifest_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ def upgrade_manifest_json(manifest: dict, manifest_schema_version: int) -> dict:
if "root_path" in doc_content:
del doc_content["root_path"]
doc_content["resource_type"] = "doc"
if "semantic_nodes" not in manifest:
manifest["semantic_nodes"] = {}
if "semantic_models" not in manifest:
manifest["semantic_models"] = {}
return manifest
2 changes: 1 addition & 1 deletion core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ def process_refs(self, current_project: str):
if metric.created_at < self.started_at:
continue
_process_refs(self.manifest, current_project, metric)
for semantic_model in self.manifest.semantic_nodes.values():
for semantic_model in self.manifest.semantic_models.values():
if semantic_model.created_at < self.started_at:
continue
_process_refs(self.manifest, current_project, semantic_model)
Expand Down
6 changes: 3 additions & 3 deletions schemas/dbt/manifest/v10.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"metrics",
"groups",
"selectors",
"semantic_nodes"
"semantic_models"
],
"properties": {
"metadata": {
Expand Down Expand Up @@ -203,7 +203,7 @@
],
"description": "A mapping from group names to their nodes"
},
"semantic_nodes": {
"semantic_models": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/SemanticModel"
Expand All @@ -212,7 +212,7 @@
}
},
"additionalProperties": false,
"description": "WritableManifest(metadata: dbt.contracts.graph.manifest.ManifestMetadata, nodes: Mapping[str, Union[dbt.contracts.graph.nodes.AnalysisNode, dbt.contracts.graph.nodes.SingularTestNode, dbt.contracts.graph.nodes.HookNode, dbt.contracts.graph.nodes.ModelNode, dbt.contracts.graph.nodes.RPCNode, dbt.contracts.graph.nodes.SqlNode, dbt.contracts.graph.nodes.GenericTestNode, dbt.contracts.graph.nodes.SnapshotNode, dbt.contracts.graph.nodes.SeedNode]], sources: Mapping[str, dbt.contracts.graph.nodes.SourceDefinition], macros: Mapping[str, dbt.contracts.graph.nodes.Macro], docs: Mapping[str, dbt.contracts.graph.nodes.Documentation], exposures: Mapping[str, dbt.contracts.graph.nodes.Exposure], metrics: Mapping[str, dbt.contracts.graph.nodes.Metric], groups: Mapping[str, dbt.contracts.graph.nodes.Group], selectors: Mapping[str, Any], disabled: Union[Mapping[str, List[Union[dbt.contracts.graph.nodes.AnalysisNode, dbt.contracts.graph.nodes.SingularTestNode, dbt.contracts.graph.nodes.HookNode, dbt.contracts.graph.nodes.ModelNode, dbt.contracts.graph.nodes.RPCNode, dbt.contracts.graph.nodes.SqlNode, dbt.contracts.graph.nodes.GenericTestNode, dbt.contracts.graph.nodes.SnapshotNode, dbt.contracts.graph.nodes.SeedNode, dbt.contracts.graph.nodes.SourceDefinition, dbt.contracts.graph.nodes.Exposure, dbt.contracts.graph.nodes.Metric]]], NoneType], parent_map: Union[Dict[str, List[str]], NoneType], child_map: Union[Dict[str, List[str]], NoneType], group_map: Union[Dict[str, List[str]], NoneType], semantic_nodes: Mapping[str, dbt.contracts.graph.nodes.SemanticModel])",
"description": "WritableManifest(metadata: dbt.contracts.graph.manifest.ManifestMetadata, nodes: Mapping[str, Union[dbt.contracts.graph.nodes.AnalysisNode, dbt.contracts.graph.nodes.SingularTestNode, dbt.contracts.graph.nodes.HookNode, dbt.contracts.graph.nodes.ModelNode, dbt.contracts.graph.nodes.RPCNode, dbt.contracts.graph.nodes.SqlNode, dbt.contracts.graph.nodes.GenericTestNode, dbt.contracts.graph.nodes.SnapshotNode, dbt.contracts.graph.nodes.SeedNode]], sources: Mapping[str, dbt.contracts.graph.nodes.SourceDefinition], macros: Mapping[str, dbt.contracts.graph.nodes.Macro], docs: Mapping[str, dbt.contracts.graph.nodes.Documentation], exposures: Mapping[str, dbt.contracts.graph.nodes.Exposure], metrics: Mapping[str, dbt.contracts.graph.nodes.Metric], groups: Mapping[str, dbt.contracts.graph.nodes.Group], selectors: Mapping[str, Any], disabled: Union[Mapping[str, List[Union[dbt.contracts.graph.nodes.AnalysisNode, dbt.contracts.graph.nodes.SingularTestNode, dbt.contracts.graph.nodes.HookNode, dbt.contracts.graph.nodes.ModelNode, dbt.contracts.graph.nodes.RPCNode, dbt.contracts.graph.nodes.SqlNode, dbt.contracts.graph.nodes.GenericTestNode, dbt.contracts.graph.nodes.SnapshotNode, dbt.contracts.graph.nodes.SeedNode, dbt.contracts.graph.nodes.SourceDefinition, dbt.contracts.graph.nodes.Exposure, dbt.contracts.graph.nodes.Metric]]], NoneType], parent_map: Union[Dict[str, List[str]], NoneType], child_map: Union[Dict[str, List[str]], NoneType], group_map: Union[Dict[str, List[str]], NoneType], semantic_models: Mapping[str, dbt.contracts.graph.nodes.SemanticModel])",
"definitions": {
"ManifestMetadata": {
"type": "object",
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/artifacts/expected_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False):
"doc.test.macro_arg_info": ANY,
},
"disabled": {},
"semantic_nodes": {},
"semantic_models": {},
}


Expand Down Expand Up @@ -1445,7 +1445,7 @@ def expected_references_manifest(project):
],
}
},
"semantic_nodes": {},
"semantic_models": {},
}


Expand Down Expand Up @@ -1924,5 +1924,5 @@ def expected_versions_manifest(project):
},
"disabled": {},
"macros": {},
"semantic_nodes": {},
"semantic_models": {},
}
2 changes: 1 addition & 1 deletion tests/functional/artifacts/test_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def verify_manifest(project, expected_manifest, start_time, manifest_schema_path
"disabled",
"exposures",
"selectors",
"semantic_nodes",
"semantic_models",
}

assert set(manifest.keys()) == manifest_keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def test_semantic_model_parsing(self, project):
assert result.success
assert isinstance(result.result, Manifest)
manifest = result.result
assert len(manifest.semantic_nodes) == 1
semantic_model = manifest.semantic_nodes["semanticmodel.test.revenue"]
assert len(manifest.semantic_models) == 1
semantic_model = manifest.semantic_models["semanticmodel.test.revenue"]
assert semantic_model.node_relation.alias == "fct_revenue"
assert (
semantic_model.node_relation.relation_name
Expand All @@ -83,5 +83,5 @@ def test_semantic_model_partial_parsing(self, project):

# Finally, verify that the manifest reflects the partially parsed change
manifest = result.result
semantic_model = manifest.semantic_nodes["semanticmodel.test.revenue"]
semantic_model = manifest.semantic_models["semanticmodel.test.revenue"]
assert semantic_model.dimensions[0].type_params.time_granularity == TimeGranularity.WEEK
24 changes: 12 additions & 12 deletions tests/unit/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def setUp(self):
),
}

self.semantic_nodes = {}
self.semantic_models = {}

for exposure in self.exposures.values():
exposure.validate(exposure.to_dict(omit_none=True))
Expand Down Expand Up @@ -366,7 +366,7 @@ def test_no_nodes(self):
metrics={},
selectors={},
metadata=ManifestMetadata(generated_at=datetime.utcnow()),
semantic_nodes={},
semantic_models={},
)

invocation_id = dbt.events.functions.EVENT_MANAGER.invocation_id
Expand All @@ -392,7 +392,7 @@ def test_no_nodes(self):
},
"docs": {},
"disabled": {},
"semantic_nodes": {},
"semantic_models": {},
},
)

Expand Down Expand Up @@ -476,7 +476,7 @@ def test_build_flat_graph(self):
flat_metrics = flat_graph["metrics"]
flat_nodes = flat_graph["nodes"]
flat_sources = flat_graph["sources"]
flat_semantic_nodes = flat_graph["semantic_nodes"]
flat_semantic_models = flat_graph["semantic_models"]
self.assertEqual(
set(flat_graph),
set(
Expand All @@ -486,7 +486,7 @@ def test_build_flat_graph(self):
"nodes",
"sources",
"metrics",
"semantic_nodes",
"semantic_models",
]
),
)
Expand All @@ -495,7 +495,7 @@ def test_build_flat_graph(self):
self.assertEqual(set(flat_metrics), set(self.metrics))
self.assertEqual(set(flat_nodes), set(self.nested_nodes))
self.assertEqual(set(flat_sources), set(self.sources))
self.assertEqual(set(flat_semantic_nodes), set(self.semantic_nodes))
self.assertEqual(set(flat_semantic_models), set(self.semantic_models))
for node in flat_nodes.values():
self.assertEqual(frozenset(node), REQUIRED_PARSED_NODE_KEYS)

Expand Down Expand Up @@ -542,7 +542,7 @@ def test_no_nodes_with_metadata(self, mock_user):
metadata=metadata,
files={},
exposures={},
semantic_nodes={},
semantic_models={},
)

self.assertEqual(
Expand Down Expand Up @@ -571,7 +571,7 @@ def test_no_nodes_with_metadata(self, mock_user):
"env": {ENV_KEY_NAME: "value"},
},
"disabled": {},
"semantic_nodes": {},
"semantic_models": {},
},
)

Expand Down Expand Up @@ -919,7 +919,7 @@ def test_no_nodes(self):
metadata=metadata,
files={},
exposures={},
semantic_nodes={},
semantic_models={},
)
self.assertEqual(
manifest.writable_manifest().to_dict(omit_none=True),
Expand All @@ -943,7 +943,7 @@ def test_no_nodes(self):
},
"docs": {},
"disabled": {},
"semantic_nodes": {},
"semantic_models": {},
},
)

Expand Down Expand Up @@ -1011,7 +1011,7 @@ def test_build_flat_graph(self):
selectors={},
files={},
exposures={},
semantic_nodes={},
semantic_models={},
)
manifest.build_flat_graph()
flat_graph = manifest.flat_graph
Expand All @@ -1025,7 +1025,7 @@ def test_build_flat_graph(self):
"metrics",
"nodes",
"sources",
"semantic_nodes",
"semantic_models",
]
),
)
Expand Down

0 comments on commit e771ff5

Please sign in to comment.