Skip to content

Commit

Permalink
added spec changes for constant properties
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamDee committed Nov 26, 2023
1 parent 130974b commit 6d61014
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 8 additions & 0 deletions dbt_semantic_interfaces/implementations/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ def parse(window: str) -> PydanticMetricTimeWindow:
)


class PydanticConstantPropertyInput(HashableBaseModel):
"""Input of a constant property used in conversion metrics."""

base_property: str
conversion_property: str


class PydanticMetricInput(HashableBaseModel):
"""Provides a pointer to a metric along with the additional properties used on that metric."""

Expand Down Expand Up @@ -146,6 +153,7 @@ class PydanticConversionTypeParams(HashableBaseModel):
entity: str
calculation: ConversionCalculationType = ConversionCalculationType.CONVERSION_RATE
window: Optional[PydanticMetricTimeWindow]
constant_properties: Optional[List[PydanticConstantPropertyInput]]

@property
def base_measure_reference(self) -> MeasureReference:
Expand Down
25 changes: 24 additions & 1 deletion dbt_semantic_interfaces/protocols/metric.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
from typing import List, Optional, Protocol, Sequence

from dbt_semantic_interfaces.protocols.metadata import Metadata
from dbt_semantic_interfaces.protocols.where_filter import WhereFilterIntersection
Expand Down Expand Up @@ -117,6 +117,23 @@ def post_aggregation_reference(self) -> MetricReference:
pass


class ConstantPropertyInput(Protocol):
"""Provides the constant property values for conversion metrics.
The specified property will be a reference of a dimension/entity.
"""

@property
@abstractmethod
def base_property(self) -> str: # noqa: D
pass

@property
@abstractmethod
def conversion_property(self) -> str: # noqa: D
pass


class ConversionTypeParams(Protocol):
"""Type params to provide context for conversion metrics properties."""

Expand Down Expand Up @@ -162,6 +179,12 @@ def conversion_measure_reference(self) -> MeasureReference:
"""Return the measure reference associated with the conversion measure."""
pass

@property
@abstractmethod
def constant_properties(self) -> Optional[List[ConstantPropertyInput]]:
"""Return the list of defined constant properties."""
pass


class MetricTypeParams(Protocol):
"""Type params add additional context to certain metric types (the context depends on the metric type)."""
Expand Down

0 comments on commit 6d61014

Please sign in to comment.