Skip to content

Commit

Permalink
Add "other" relation to reffable node classes (#7645)
Browse files Browse the repository at this point in the history
  • Loading branch information
stu-k authored May 17, 2023
1 parent dea3181 commit f6e5582
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20230515-152107.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Add other relation to reffable nodes
time: 2023-05-15T15:21:07.808892-05:00
custom:
Author: stu-k
Issue: "7550"
2 changes: 2 additions & 0 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,8 @@ 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 "state_relation" in node:
del node["state_relation"]
return dct


Expand Down
14 changes: 14 additions & 0 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,17 @@ def add_public_node(self, value: str):
self.public_nodes.append(value)


@dataclass
class StateRelation(dbtClassMixin):
alias: str
database: Optional[str]
schema: str

@property
def identifier(self):
return self.alias


@dataclass
class ParsedNodeMandatory(GraphNode, HasRelationMetadata, Replaceable):
alias: str
Expand Down Expand Up @@ -557,6 +568,7 @@ class ModelNode(CompiledNode):
constraints: List[ModelLevelConstraint] = field(default_factory=list)
version: Optional[NodeVersion] = None
latest_version: Optional[NodeVersion] = None
state_relation: Optional[StateRelation] = None

@property
def is_latest_version(self) -> bool:
Expand Down Expand Up @@ -739,6 +751,7 @@ class SeedNode(ParsedNode): # No SQLDefaults!
# and we need the root_path to load the seed later
root_path: Optional[str] = None
depends_on: MacroDependsOn = field(default_factory=MacroDependsOn)
state_relation: Optional[StateRelation] = None

def same_seeds(self, other: "SeedNode") -> bool:
# for seeds, we check the hashes. If the hashes are different types,
Expand Down Expand Up @@ -937,6 +950,7 @@ class IntermediateSnapshotNode(CompiledNode):
class SnapshotNode(CompiledNode):
resource_type: NodeType = field(metadata={"restrict": [NodeType.Snapshot]})
config: SnapshotConfig
state_relation: Optional[StateRelation] = None


# ====================================
Expand Down
1 change: 1 addition & 0 deletions test/unit/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"version",
"latest_version",
"constraints",
"state_relation",
}
)

Expand Down

0 comments on commit f6e5582

Please sign in to comment.