Skip to content

Commit

Permalink
Move Exposure data parts to dbt/artifacts (#9494)
Browse files Browse the repository at this point in the history
* Move `ExposureType` to dbt/artifacts

* Move `MaturityType` to dbt/artifacts

* Move `ExposureConfig` to dbt/artifacts

* Move data parts of `Exposure` node class to dbt/artifacts

* Update leftover incorrect imports of `Owner` resource

There were a few places in the code base that were importing `Owner`
from `unparsed` or `nodes`. The places importing from `unparsed` were
working because `unparsed` itself was correctly importing from
`artifacts.resources`. However in places where it was being imported
from `nodes`, an exception was being raised because in the previous
commit we removed the import of `Owner` in `nodes` because it was
no longer needed.
  • Loading branch information
QMalcolm authored Feb 1, 2024
1 parent 0836095 commit 2d59a51
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 60 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240130-161637.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Move data parts of `Exposure` class to dbt/artifacts
time: 2024-01-30T16:16:37.176038-08:00
custom:
Author: QMalcolm
Issue: "9380"
6 changes: 6 additions & 0 deletions core/dbt/artifacts/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# alias to latest resource definitions
from dbt.artifacts.resources.v1.components import DependsOn, NodeVersion, RefArgs
from dbt.artifacts.resources.v1.documentation import Documentation
from dbt.artifacts.resources.v1.exposure import (
Exposure,
ExposureConfig,
ExposureType,
MaturityType,
)
from dbt.artifacts.resources.v1.macro import Macro, MacroDependsOn, MacroArgument
from dbt.artifacts.resources.v1.docs import Docs
from dbt.artifacts.resources.v1.group import Group
Expand Down
48 changes: 48 additions & 0 deletions core/dbt/artifacts/resources/v1/exposure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from dataclasses import dataclass, field
from dbt.artifacts.resources.base import GraphResource
from dbt.artifacts.resources.types import NodeType
from dbt.artifacts.resources.v1.components import DependsOn, RefArgs
from dbt.artifacts.resources.v1.owner import Owner
from dbt_common.contracts.config.base import BaseConfig
from dbt_common.dataclass_schema import StrEnum
import time
from typing import Any, Dict, List, Literal, Optional


class ExposureType(StrEnum):
Dashboard = "dashboard"
Notebook = "notebook"
Analysis = "analysis"
ML = "ml"
Application = "application"


class MaturityType(StrEnum):
Low = "low"
Medium = "medium"
High = "high"


@dataclass
class ExposureConfig(BaseConfig):
enabled: bool = True


@dataclass
class Exposure(GraphResource):
type: ExposureType
owner: Owner
resource_type: Literal[NodeType.Exposure]
description: str = ""
label: Optional[str] = None
maturity: Optional[MaturityType] = None
meta: Dict[str, Any] = field(default_factory=dict)
tags: List[str] = field(default_factory=list)
config: ExposureConfig = field(default_factory=ExposureConfig)
unrendered_config: Dict[str, Any] = field(default_factory=dict)
url: Optional[str] = None
depends_on: DependsOn = field(default_factory=DependsOn)
refs: List[RefArgs] = field(default_factory=list)
sources: List[List[str]] = field(default_factory=list)
metrics: List[List[str]] = field(default_factory=list)
created_at: float = field(default_factory=lambda: time.time())
2 changes: 1 addition & 1 deletion core/dbt/artifacts/schemas/manifest/v12/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from dbt.artifacts.schemas.upgrades import upgrade_manifest_json
from dbt.artifacts.resources import (
Documentation,
Exposure,
Group,
Macro,
Metric,
Expand All @@ -22,7 +23,6 @@
from dbt import tracking
from dbt.flags import get_flags
from dbt.contracts.graph.nodes import (
Exposure,
GraphMemberNode,
ManifestNode,
SourceDefinition,
Expand Down
6 changes: 1 addition & 5 deletions core/dbt/contracts/graph/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing_extensions import Annotated

from dbt.artifacts.resources import (
ExposureConfig,
MetricConfig,
SavedQueryConfig,
SemanticModelConfig,
Expand Down Expand Up @@ -53,11 +54,6 @@ class Hook(dbtClassMixin, Replaceable):
index: Optional[int] = None


@dataclass
class ExposureConfig(BaseConfig):
enabled: bool = True


@dataclass
class SourceConfig(BaseConfig):
enabled: bool = True
Expand Down
24 changes: 2 additions & 22 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@
from dbt_common.clients.system import write_file
from dbt.contracts.files import FileHash
from dbt.contracts.graph.unparsed import (
ExposureType,
ExternalTable,
FreshnessThreshold,
HasYamlMetadata,
MaturityType,
Owner,
Quoting,
TestDef,
UnparsedSourceDefinition,
Expand Down Expand Up @@ -74,7 +71,6 @@
SeedConfig,
TestConfig,
SourceConfig,
ExposureConfig,
EmptySnapshotConfig,
SnapshotConfig,
UnitTestConfig,
Expand All @@ -85,6 +81,7 @@
BaseResource,
DependsOn,
Docs,
Exposure as ExposureResource,
MacroDependsOn,
MacroArgument,
Documentation as DocumentationResource,
Expand Down Expand Up @@ -1378,24 +1375,7 @@ def group(self):


@dataclass
class Exposure(GraphNode[GraphResource]):
type: ExposureType
owner: Owner
resource_type: Literal[NodeType.Exposure]
description: str = ""
label: Optional[str] = None
maturity: Optional[MaturityType] = None
meta: Dict[str, Any] = field(default_factory=dict)
tags: List[str] = field(default_factory=list)
config: ExposureConfig = field(default_factory=ExposureConfig)
unrendered_config: Dict[str, Any] = field(default_factory=dict)
url: Optional[str] = None
depends_on: DependsOn = field(default_factory=DependsOn)
refs: List[RefArgsResource] = field(default_factory=list)
sources: List[List[str]] = field(default_factory=list)
metrics: List[List[str]] = field(default_factory=list)
created_at: float = field(default_factory=lambda: time.time())

class Exposure(GraphNode[ExposureResource], ExposureResource):
@property
def depends_on_nodes(self):
return self.depends_on.nodes
Expand Down
16 changes: 2 additions & 14 deletions core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from dbt.artifacts.resources import (
Defaults,
DimensionValidityParams,
ExposureType,
MaturityType,
MeasureAggregationParameters,
)
from dbt.contracts.util import (
Expand Down Expand Up @@ -506,20 +508,6 @@ def __le__(self, other):
return self == other or self < other


class ExposureType(StrEnum):
Dashboard = "dashboard"
Notebook = "notebook"
Analysis = "analysis"
ML = "ml"
Application = "application"


class MaturityType(StrEnum):
Low = "low"
Medium = "medium"
High = "high"


@dataclass
class UnparsedExposure(dbtClassMixin, Replaceable):
name: str
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/graph/selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu
elif unique_id in manifest.sources:
previous_node = manifest.sources[unique_id]
elif unique_id in manifest.exposures:
previous_node = manifest.exposures[unique_id]
previous_node = Exposure.from_resource(manifest.exposures[unique_id])
elif unique_id in manifest.metrics:
previous_node = Metric.from_resource(manifest.metrics[unique_id])
elif unique_id in manifest.semantic_models:
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
Entity,
Export,
ExportConfig,
ExposureConfig,
Measure,
MetricConfig,
MetricInput,
Expand All @@ -49,7 +50,6 @@
from dbt.exceptions import YamlParseDictError, JSONValidationError
from dbt.context.providers import generate_parse_exposure, generate_parse_semantic_models

from dbt.contracts.graph.model_config import ExposureConfig
from dbt.context.context_config import (
BaseContextConfigGenerator,
ContextConfigGenerator,
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/exposures/test_exposure_configs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from dbt_common.dataclass_schema import ValidationError

from dbt.contracts.graph.model_config import ExposureConfig
from dbt.artifacts.resources import ExposureConfig
from dbt_common.dataclass_schema import ValidationError

from dbt.tests.util import run_dbt, update_config_file, get_manifest
from tests.functional.exposures.fixtures import (
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_contracts_graph_parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
from dbt.artifacts.resources import (
Dimension,
Entity,
ExposureConfig,
ExposureType,
MaturityType,
Measure,
MetricInputMeasure,
MetricTypeParams,
Owner,
RefArgs,
)
from dbt.node_types import NodeType, AccessType
Expand All @@ -21,7 +25,6 @@
TestConfig,
SnapshotConfig,
SourceConfig,
ExposureConfig,
EmptySnapshotConfig,
Hook,
)
Expand All @@ -41,14 +44,11 @@
SourceDefinition,
Documentation,
HookNode,
Owner,
TestMetadata,
SemanticModel,
)
from dbt.contracts.graph.unparsed import (
ExposureType,
FreshnessThreshold,
MaturityType,
Quoting,
Time,
TimePeriod,
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/test_contracts_graph_unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
UnparsedModelUpdate,
Docs,
UnparsedExposure,
MaturityType,
Owner,
ExposureType,
UnparsedMetric,
UnparsedMetricTypeParams,
UnparsedMetricInputMeasure,
UnparsedVersion,
)
from dbt.artifacts.resources import ExposureType, MaturityType, Owner
from dbt.artifacts.schemas.results import FreshnessStatus
from dbt.node_types import NodeType
from .utils import ContractTestCase
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_graph_selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
)
from dbt.contracts.graph.manifest import Manifest, ManifestMetadata
from dbt.artifacts.resources import (
ExposureType,
MetricInputMeasure,
MetricTypeParams,
NodeRelation,
Owner,
QueryParams,
)
from dbt.contracts.graph.unparsed import (
ExposureType,
Owner,
UnitTestInputFixture,
UnitTestOutputFixture,
)
Expand Down
8 changes: 3 additions & 5 deletions tests/unit/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@
Group,
)
from dbt.artifacts.resources import (
ExposureType,
MaturityType,
MetricInputMeasure,
MetricTypeParams,
Owner,
RefArgs,
WhereFilter,
WhereFilterIntersection,
)
from dbt.contracts.graph.unparsed import (
ExposureType,
Owner,
MaturityType,
)
import dbt_common.invocation
from dbt_common.events.functions import reset_metadata_vars
from dbt.exceptions import AmbiguousResourceNameRefError
Expand Down

0 comments on commit 2d59a51

Please sign in to comment.