Skip to content

Commit

Permalink
expose meta in SemanticModel
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamDee committed Jan 20, 2024
1 parent a288535 commit 1b9bc27
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
12 changes: 11 additions & 1 deletion dbt_semantic_interfaces/implementations/semantic_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, List, Optional, Sequence
from typing import Any, Dict, List, Optional, Sequence

from typing_extensions import override

Expand All @@ -15,6 +15,7 @@
from dbt_semantic_interfaces.protocols import (
ProtocolHint,
SemanticModel,
SemanticModelConfig,
SemanticModelDefaults,
)
from dbt_semantic_interfaces.references import (
Expand Down Expand Up @@ -76,6 +77,14 @@ def _implements_protocol(self) -> SemanticModelDefaults: # noqa: D
agg_time_dimension: Optional[str]


class PydanticSemanticModelConfig(HashableBaseModel, ProtocolHint[SemanticModelConfig]): # noqa: D
@override
def _implements_protocol(self) -> SemanticModelConfig: # noqa: D
return self

meta: Dict[str, Any] = {}


class PydanticSemanticModel(HashableBaseModel, ModelWithMetadataParsing, ProtocolHint[SemanticModel]):
"""Describes a semantic model."""

Expand All @@ -95,6 +104,7 @@ def _implements_protocol(self) -> SemanticModel:
label: Optional[str] = None

metadata: Optional[PydanticMetadata]
config: Optional[PydanticSemanticModelConfig]

@property
def entity_references(self) -> List[LinkableElementReference]: # noqa: D
Expand Down
1 change: 1 addition & 0 deletions dbt_semantic_interfaces/protocols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
)
from dbt_semantic_interfaces.protocols.semantic_model import ( # noqa:F401
SemanticModel,
SemanticModelConfig,
SemanticModelDefaults,
SemanticModelT,
)
Expand Down
17 changes: 16 additions & 1 deletion dbt_semantic_interfaces/protocols/semantic_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from abc import abstractmethod
from typing import Optional, Protocol, Sequence, TypeVar
from typing import Any, Dict, Optional, Protocol, Sequence, TypeVar

from dbt_semantic_interfaces.protocols.dimension import Dimension
from dbt_semantic_interfaces.protocols.entity import Entity
Expand Down Expand Up @@ -50,6 +50,16 @@ def agg_time_dimension(self) -> Optional[str]:
pass


class SemanticModelConfig(Protocol): # noqa: D
"""The config property allows you to configure additional resources/metadata."""

@property
@abstractmethod
def meta(self) -> Dict[str, Any]:
"""The meta field can be used to set metadata for a resource."""
pass


class SemanticModel(Protocol):
"""Describes a semantic model."""

Expand Down Expand Up @@ -159,6 +169,11 @@ def reference(self) -> SemanticModelReference:
def metadata(self) -> Optional[Metadata]: # noqa: D
pass

@property
@abstractmethod
def config(self) -> Optional[SemanticModelConfig]: # noqa: D
pass

@abstractmethod
def checked_agg_time_dimension_for_measure(self, measure_reference: MeasureReference) -> TimeDimensionReference:
"""Returns the `TimeDimensionReference` what a measure should use for it's `agg_time_dimension`.
Expand Down

0 comments on commit 1b9bc27

Please sign in to comment.