-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Define Macro and Group resources in dbt/artifacts #9439
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ae2b362
first pass: move Macro to dbt/artifacts
MichelleArk a6aaba6
changelog entry
MichelleArk 4fbc2b8
move Group resource to dbt/artifacts and rename BaseArtifactNode to B…
MichelleArk cdfdb7a
remove contracts.graph.nodes references in dbt.artifacts
MichelleArk 90f2155
code quality fix
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: Define Macro resource in dbt/artifacts | ||
time: 2024-01-25T09:54:53.974332-05:00 | ||
custom: | ||
Author: michelleark | ||
Issue: "9382" |
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,10 @@ | ||
from dataclasses import dataclass | ||
from dbt_common.dataclass_schema import dbtClassMixin | ||
from dbt_common.contracts.util import Replaceable | ||
from typing import Optional | ||
|
||
|
||
@dataclass | ||
class Docs(dbtClassMixin, Replaceable): | ||
show: bool = True | ||
node_color: Optional[str] = None |
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,40 @@ | ||
from dataclasses import dataclass, field | ||
import time | ||
from typing import Literal, List, Dict, Optional, Any | ||
|
||
from dbt_common.contracts.util import Replaceable | ||
from dbt_common.dataclass_schema import dbtClassMixin | ||
from dbt.artifacts.resources.base import BaseArtifactNode | ||
from dbt.artifacts.resources.types import NodeType, ModelLanguage | ||
from dbt.artifacts.resources.v1.docs import Docs | ||
|
||
|
||
@dataclass | ||
class MacroArgument(dbtClassMixin): | ||
name: str | ||
type: Optional[str] = None | ||
description: str = "" | ||
|
||
|
||
@dataclass | ||
class MacroDependsOn(dbtClassMixin, Replaceable): | ||
macros: List[str] = field(default_factory=list) | ||
|
||
# 'in' on lists is O(n) so this is O(n^2) for # of macros | ||
def add_macro(self, value: str): | ||
if value not in self.macros: | ||
self.macros.append(value) | ||
|
||
|
||
@dataclass | ||
class Macro(BaseArtifactNode): | ||
macro_sql: str | ||
resource_type: Literal[NodeType.Macro] | ||
depends_on: MacroDependsOn = field(default_factory=MacroDependsOn) | ||
description: str = "" | ||
meta: Dict[str, Any] = field(default_factory=dict) | ||
docs: Docs = field(default_factory=Docs) | ||
patch_path: Optional[str] = None | ||
arguments: List[MacroArgument] = field(default_factory=list) | ||
created_at: float = field(default_factory=lambda: time.time()) | ||
supported_languages: Optional[List[ModelLanguage]] = None |
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
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.
Went back and forth on whether this method belongs in dbt/artifacts given it is mutating / not read-only. An alternative would be to define the method more directly on the internal
Macro
node class.Decided to leave it as-is for now because
DependsOn
inherits fromMacroDependsOn
. We should revisit a design once we moveDependsOn
though.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.
For those looking in @MichelleArk and I have talked about this a bit in DMs. In my PR #9460 I plan on moving
DependsOn
in full over to artifacts. We plan in the future to revist the design of bothMacroDependsOn
andDependsOn
to perhaps simplify and improve them.