Skip to content

Commit

Permalink
first pass: from_writable_manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Feb 9, 2024
1 parent 15dcb9a commit d74f4f8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
51 changes: 51 additions & 0 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,57 @@ def build_group_map(self):
group_map[node.group].append(node.unique_id)
self.group_map = group_map

@classmethod
def from_writable_manifest(cls, writable_manifest: WritableManifest) -> "Manifest":
manifest = Manifest(

Check warning on line 1025 in core/dbt/contracts/graph/manifest.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/contracts/graph/manifest.py#L1025

Added line #L1025 was not covered by tests
# TODO: update these as corresponding resources are created
nodes={node_id: node for node_id, node in writable_manifest.nodes.items()},
disabled={
disabled_node_id: disabled_node
for disabled_node_id, disabled_node in writable_manifest.disabled.items()
}
if writable_manifest.disabled is not None
else {},
unit_tests={
unit_test_id: unit_test
for unit_test_id, unit_test in writable_manifest.unit_tests.items()
},
sources={
source_id: SourceDefinition.from_resource(source)
for source_id, source in writable_manifest.sources.items()
},
macros={
macro_id: Macro.from_resource(macro)
for macro_id, macro in writable_manifest.macros.items()
},
docs={
doc_id: Documentation.from_resource(doc)
for doc_id, doc in writable_manifest.docs.items()
},
exposures={
exposure_id: Exposure.from_resource(exposure)
for exposure_id, exposure in writable_manifest.exposures.items()
},
metrics={
metric_id: Metric.from_resource(metric)
for metric_id, metric in writable_manifest.metrics.items()
},
groups={
group_id: Group.from_resource(group)
for group_id, group in writable_manifest.groups.items()
},
selectors={
selector_id: selector
for selector_id, selector in writable_manifest.selectors.items()
},
semantic_models={
semantic_model_id: SemanticModel.from_resource(semantic_model)
for semantic_model_id, semantic_model in writable_manifest.semantic_models.items()
},
)

return manifest

Check warning on line 1072 in core/dbt/contracts/graph/manifest.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/contracts/graph/manifest.py#L1072

Added line #L1072 was not covered by tests

def writable_manifest(self) -> "WritableManifest":
self.build_parent_and_child_maps()
self.build_group_map()
Expand Down
8 changes: 5 additions & 3 deletions core/dbt/contracts/state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pathlib import Path
from typing import Optional

from dbt.contracts.graph.manifest import WritableManifest
from dbt.contracts.graph.manifest import Manifest
from dbt.artifacts.schemas.manifest import WritableManifest
from dbt.artifacts.schemas.freshness import FreshnessExecutionResultArtifact
from dbt.artifacts.schemas.run import RunResultsArtifact
from dbt_common.events.functions import fire_event
Expand All @@ -24,7 +25,7 @@ def __init__(self, state_path: Path, target_path: Path, project_root: Path) -> N
self.state_path: Path = state_path
self.target_path: Path = target_path
self.project_root: Path = project_root
self.manifest: Optional[WritableManifest] = None
self.manifest: Optional[Manifest] = None
self.results: Optional[RunResultsArtifact] = None
self.sources: Optional[FreshnessExecutionResultArtifact] = None
self.sources_current: Optional[FreshnessExecutionResultArtifact] = None
Expand All @@ -36,7 +37,8 @@ def __init__(self, state_path: Path, target_path: Path, project_root: Path) -> N
manifest_path = self.project_root / self.state_path / "manifest.json"
if manifest_path.exists() and manifest_path.is_file():
try:
self.manifest = WritableManifest.read_and_check_versions(str(manifest_path))
writable_manifest = WritableManifest.read_and_check_versions(str(manifest_path))
self.manifest = Manifest.from_writable_manifest(writable_manifest)

Check warning on line 41 in core/dbt/contracts/state.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/contracts/state.py#L40-L41

Added lines #L40 - L41 were not covered by tests
except IncompatibleSchemaError as exc:
exc.add_filename(str(manifest_path))
raise
Expand Down

0 comments on commit d74f4f8

Please sign in to comment.