From 6d61014c45a142f2e2cdd2cc1fa30565eb42c3f8 Mon Sep 17 00:00:00 2001 From: Will Deng Date: Sun, 26 Nov 2023 15:05:29 -0500 Subject: [PATCH] added spec changes for constant properties --- .../implementations/metric.py | 8 ++++++ dbt_semantic_interfaces/protocols/metric.py | 25 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dbt_semantic_interfaces/implementations/metric.py b/dbt_semantic_interfaces/implementations/metric.py index 3749e1a9..a3c77277 100644 --- a/dbt_semantic_interfaces/implementations/metric.py +++ b/dbt_semantic_interfaces/implementations/metric.py @@ -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.""" @@ -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: diff --git a/dbt_semantic_interfaces/protocols/metric.py b/dbt_semantic_interfaces/protocols/metric.py index 2be77e6c..16f0badb 100644 --- a/dbt_semantic_interfaces/protocols/metric.py +++ b/dbt_semantic_interfaces/protocols/metric.py @@ -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 @@ -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.""" @@ -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)."""