-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move WritableManifest to dbt/artifacts #9377
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e50a38e
move manifest artifacts to dbt/artifacts
MichelleArk c7c1492
move upgrade_manifest_json + Documentation to dbt/artifacts
MichelleArk 92c1f6a
rename node -> contract in dbt/artifacts
MichelleArk 7fb92b2
refactor refable, executable, versioned
MichelleArk 27992fe
rename contracts -> resources
MichelleArk 61f4711
Merge branch 'main' into move-manifest-to-artifacts
MichelleArk 6ff978c
changelog entry
MichelleArk 4f264e4
move Documentation to resources/v1 + set up latest aliasing
MichelleArk 89e48cb
set up version dir structure in dbt/artifacts/schemas
MichelleArk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Under the Hood | ||
body: Move WritableManifest + Documentation to dbt/artifacts | ||
time: 2024-01-23T14:22:56.488252-05:00 | ||
custom: | ||
Author: michelleark | ||
Issue: 9378 9379 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from dbt.artifacts.resources.base import BaseArtifactNode | ||
|
||
# alias to latest resource definitions | ||
from dbt.artifacts.resources.v1.documentation import Documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from dataclasses import dataclass | ||
from dbt_common.dataclass_schema import dbtClassMixin | ||
from dbt_common.contracts.util import Replaceable | ||
|
||
from dbt.artifacts.resources.types import NodeType | ||
|
||
|
||
@dataclass | ||
class BaseArtifactNode(dbtClassMixin, Replaceable): | ||
name: str | ||
resource_type: NodeType | ||
package_name: str | ||
path: str | ||
original_file_path: str | ||
unique_id: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from dbt_common.dataclass_schema import StrEnum | ||
|
||
|
||
class AccessType(StrEnum): | ||
Private = "private" | ||
Protected = "protected" | ||
Public = "public" | ||
|
||
@classmethod | ||
def is_valid(cls, item): | ||
try: | ||
cls(item) | ||
except ValueError: | ||
return False | ||
return True | ||
|
||
|
||
class NodeType(StrEnum): | ||
Model = "model" | ||
Analysis = "analysis" | ||
Test = "test" | ||
Snapshot = "snapshot" | ||
Operation = "operation" | ||
Seed = "seed" | ||
# TODO: rm? | ||
RPCCall = "rpc" | ||
SqlOperation = "sql_operation" | ||
Documentation = "doc" | ||
Source = "source" | ||
Macro = "macro" | ||
Exposure = "exposure" | ||
Metric = "metric" | ||
Group = "group" | ||
SavedQuery = "saved_query" | ||
SemanticModel = "semantic_model" | ||
Unit = "unit_test" | ||
Fixture = "fixture" | ||
|
||
def pluralize(self) -> str: | ||
if self is self.Analysis: | ||
return "analyses" | ||
elif self is self.SavedQuery: | ||
return "saved_queries" | ||
return f"{self}s" | ||
|
||
|
||
class RunHookType(StrEnum): | ||
Start = "on-run-start" | ||
End = "on-run-end" | ||
|
||
|
||
class ModelLanguage(StrEnum): | ||
python = "python" | ||
sql = "sql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from dataclasses import dataclass | ||
from typing import Literal | ||
|
||
from dbt.artifacts.resources.base import BaseArtifactNode | ||
from dbt.artifacts.resources.types import NodeType | ||
|
||
|
||
@dataclass | ||
class Documentation(BaseArtifactNode): | ||
resource_type: Literal[NodeType.Documentation] | ||
block_contents: str |
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# alias to latest | ||
from dbt.artifacts.schemas.catalog.v1.catalog import * # noqa |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from dbt.artifacts.schemas.freshness.v3.freshness import * # noqa |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# alias to latest | ||
from dbt.artifacts.schemas.manifest.v12.manifest import * # noqa |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Mapping, Iterable, Tuple, Optional, Dict, List, Any | ||
from uuid import UUID | ||
|
||
from dbt.artifacts.schemas.base import ( | ||
BaseArtifactMetadata, | ||
ArtifactMixin, | ||
schema_version, | ||
get_artifact_schema_version, | ||
) | ||
from dbt.artifacts.schemas.upgrades import upgrade_manifest_json | ||
from dbt.artifacts.resources import Documentation | ||
|
||
# TODO: remove usage of dbt modules other than dbt.artifacts | ||
from dbt import tracking | ||
from dbt.flags import get_flags | ||
from dbt.contracts.graph.nodes import ( | ||
Exposure, | ||
GraphMemberNode, | ||
Group, | ||
Macro, | ||
ManifestNode, | ||
Metric, | ||
SavedQuery, | ||
SemanticModel, | ||
SourceDefinition, | ||
UnitTestDefinition, | ||
) | ||
|
||
|
||
NodeEdgeMap = Dict[str, List[str]] | ||
UniqueID = str | ||
|
||
|
||
@dataclass | ||
class ManifestMetadata(BaseArtifactMetadata): | ||
"""Metadata for the manifest.""" | ||
|
||
dbt_schema_version: str = field( | ||
default_factory=lambda: str(WritableManifest.dbt_schema_version) | ||
) | ||
project_name: Optional[str] = field( | ||
default=None, | ||
metadata={ | ||
"description": "Name of the root project", | ||
}, | ||
) | ||
project_id: Optional[str] = field( | ||
default=None, | ||
metadata={ | ||
"description": "A unique identifier for the project, hashed from the project name", | ||
}, | ||
) | ||
user_id: Optional[UUID] = field( | ||
default=None, | ||
metadata={ | ||
"description": "A unique identifier for the user", | ||
}, | ||
) | ||
send_anonymous_usage_stats: Optional[bool] = field( | ||
default=None, | ||
metadata=dict( | ||
description=("Whether dbt is configured to send anonymous usage statistics") | ||
), | ||
) | ||
adapter_type: Optional[str] = field( | ||
default=None, | ||
metadata=dict(description="The type name of the adapter"), | ||
) | ||
|
||
def __post_init__(self): | ||
if tracking.active_user is None: | ||
return | ||
|
||
if self.user_id is None: | ||
self.user_id = tracking.active_user.id | ||
|
||
if self.send_anonymous_usage_stats is None: | ||
self.send_anonymous_usage_stats = get_flags().SEND_ANONYMOUS_USAGE_STATS | ||
|
||
@classmethod | ||
def default(cls): | ||
return cls( | ||
dbt_schema_version=str(WritableManifest.dbt_schema_version), | ||
) | ||
|
||
|
||
@dataclass | ||
@schema_version("manifest", 12) | ||
class WritableManifest(ArtifactMixin): | ||
nodes: Mapping[UniqueID, ManifestNode] = field( | ||
metadata=dict(description=("The nodes defined in the dbt project and its dependencies")) | ||
) | ||
sources: Mapping[UniqueID, SourceDefinition] = field( | ||
metadata=dict(description=("The sources defined in the dbt project and its dependencies")) | ||
) | ||
macros: Mapping[UniqueID, Macro] = field( | ||
metadata=dict(description=("The macros defined in the dbt project and its dependencies")) | ||
) | ||
docs: Mapping[UniqueID, Documentation] = field( | ||
metadata=dict(description=("The docs defined in the dbt project and its dependencies")) | ||
) | ||
exposures: Mapping[UniqueID, Exposure] = field( | ||
metadata=dict( | ||
description=("The exposures defined in the dbt project and its dependencies") | ||
) | ||
) | ||
metrics: Mapping[UniqueID, Metric] = field( | ||
metadata=dict(description=("The metrics defined in the dbt project and its dependencies")) | ||
) | ||
groups: Mapping[UniqueID, Group] = field( | ||
metadata=dict(description=("The groups defined in the dbt project")) | ||
) | ||
selectors: Mapping[UniqueID, Any] = field( | ||
metadata=dict(description=("The selectors defined in selectors.yml")) | ||
) | ||
disabled: Optional[Mapping[UniqueID, List[GraphMemberNode]]] = field( | ||
metadata=dict(description="A mapping of the disabled nodes in the target") | ||
) | ||
parent_map: Optional[NodeEdgeMap] = field( | ||
metadata=dict( | ||
description="A mapping from child nodes to their dependencies", | ||
) | ||
) | ||
child_map: Optional[NodeEdgeMap] = field( | ||
metadata=dict( | ||
description="A mapping from parent nodes to their dependents", | ||
) | ||
) | ||
group_map: Optional[NodeEdgeMap] = field( | ||
metadata=dict( | ||
description="A mapping from group names to their nodes", | ||
) | ||
) | ||
saved_queries: Mapping[UniqueID, SavedQuery] = field( | ||
metadata=dict(description=("The saved queries defined in the dbt project")) | ||
) | ||
semantic_models: Mapping[UniqueID, SemanticModel] = field( | ||
metadata=dict(description=("The semantic models defined in the dbt project")) | ||
) | ||
metadata: ManifestMetadata = field( | ||
metadata=dict( | ||
description="Metadata about the manifest", | ||
) | ||
) | ||
unit_tests: Mapping[UniqueID, UnitTestDefinition] = field( | ||
metadata=dict( | ||
description="The unit tests defined in the project", | ||
) | ||
) | ||
|
||
@classmethod | ||
def compatible_previous_versions(cls) -> Iterable[Tuple[str, int]]: | ||
return [ | ||
("manifest", 4), | ||
("manifest", 5), | ||
("manifest", 6), | ||
("manifest", 7), | ||
("manifest", 8), | ||
("manifest", 9), | ||
("manifest", 10), | ||
("manifest", 11), | ||
] | ||
|
||
@classmethod | ||
def upgrade_schema_version(cls, data): | ||
"""This overrides the "upgrade_schema_version" call in VersionedSchema (via | ||
ArtifactMixin) to modify the dictionary passed in from earlier versions of the manifest.""" | ||
manifest_schema_version = get_artifact_schema_version(data) | ||
if manifest_schema_version <= 10: | ||
data = upgrade_manifest_json(data, manifest_schema_version) | ||
return cls.from_dict(data) | ||
|
||
def __post_serialize__(self, dct): | ||
for unique_id, node in dct["nodes"].items(): | ||
if "config_call_dict" in node: | ||
del node["config_call_dict"] | ||
if "defer_relation" in node: | ||
del node["defer_relation"] | ||
return dct |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# alias to latest | ||
from dbt.artifacts.schemas.run.v5.run import * # noqa |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from dbt.artifacts.schemas.upgrades.upgrade_manifest import upgrade_manifest_json |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be <= 11? The current version is 12, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be! Let me make sure I haven't clobbered anything during a merge...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
our latest released version is still v11: https://schemas.getdbt.com/
This also looks consistent with whats on main: https://github.com/dbt-labs/dbt-core/blob/main/core/dbt/contracts/graph/manifest.py#L1730-L1732
I'm hesitant to bump this here because it will likely need additional testing & implementation. I'll open up an issue we can take on as part of the dbt/artifacts refactor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue: #9438