Skip to content

Commit

Permalink
Move data portion of SavedQuery class to dbt/artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
QMalcolm committed Jan 27, 2024
1 parent fd437ef commit 44a1f11
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240126-164038.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Move `SavedQuery` data definition to `dbt/artifacts`
time: 2024-01-26T16:40:38.790993-08:00
custom:
Author: QMalcolm
Issue: "9386"
1 change: 1 addition & 0 deletions core/dbt/artifacts/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Export,
ExportConfig,
QueryParams,
SavedQuery,
SavedQueryConfig,
SavedQueryMandatory,
)
Expand Down
28 changes: 27 additions & 1 deletion core/dbt/artifacts/resources/v1/saved_query.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from __future__ import annotations
import time

from dataclasses import dataclass, field
from dbt.artifacts.resources.base import GraphResource
from dbt.artifacts.resources.v1.semantic_layer_components import WhereFilterIntersection
from dbt.artifacts.resources.v1.components import DependsOn, RefArgs
from dbt.artifacts.resources.v1.semantic_layer_components import (
SourceFileMetadata,
WhereFilterIntersection,
)
from dbt_common.contracts.config.base import BaseConfig, CompareBehavior, MergeBehavior
from dbt_common.dataclass_schema import dbtClassMixin
from dbt_semantic_interfaces.type_enums.export_destination_type import ExportDestinationType
Expand Down Expand Up @@ -62,3 +67,24 @@ class SavedQueryConfig(BaseConfig):
class SavedQueryMandatory(GraphResource):
query_params: QueryParams
exports: List[Export]


@dataclass
class SavedQuery(SavedQueryMandatory):
description: Optional[str] = None
label: Optional[str] = None
metadata: Optional[SourceFileMetadata] = None
config: SavedQueryConfig = field(default_factory=SavedQueryConfig)
unrendered_config: Dict[str, Any] = field(default_factory=dict)
group: Optional[str] = None
depends_on: DependsOn = field(default_factory=DependsOn)
created_at: float = field(default_factory=lambda: time.time())
refs: List[RefArgs] = field(default_factory=list)

@property
def metrics(self) -> List[str]:
return self.query_params.metrics

@property
def depends_on_nodes(self):
return self.depends_on.nodes
23 changes: 2 additions & 21 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@
Group as GroupResource,
GraphResource,
RefArgs as RefArgsResource,
SavedQueryConfig,
SavedQueryMandatory as SavedQueryMandatoryResource,
SavedQuery as SavedQueryResource,
SourceFileMetadata as SourceFileMetadataResource,
WhereFilterIntersection as WhereFilterIntersectionResource,
)
Expand Down Expand Up @@ -1796,25 +1795,7 @@ def same_contents(self, old: Optional["SemanticModel"]) -> bool:


@dataclass
class SavedQuery(NodeInfoMixin, GraphNode, SavedQueryMandatoryResource):
description: Optional[str] = None
label: Optional[str] = None
metadata: Optional[SourceFileMetadataResource] = None
config: SavedQueryConfig = field(default_factory=SavedQueryConfig)
unrendered_config: Dict[str, Any] = field(default_factory=dict)
group: Optional[str] = None
depends_on: DependsOn = field(default_factory=DependsOn)
created_at: float = field(default_factory=lambda: time.time())
refs: List[RefArgsResource] = field(default_factory=list)

@property
def metrics(self) -> List[str]:
return self.query_params.metrics

@property
def depends_on_nodes(self):
return self.depends_on.nodes

class SavedQuery(NodeInfoMixin, GraphNode, SavedQueryResource):
def same_metrics(self, old: "SavedQuery") -> bool:
return self.query_params.metrics == old.query_params.metrics

Expand Down

0 comments on commit 44a1f11

Please sign in to comment.