From d0f9cf0462799882c6b16a14a4008a1632a559ee Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Mon, 10 Jun 2024 10:37:03 -0700 Subject: [PATCH] Add cumulative type params & period agg --- dbt_semantic_interfaces/implementations/metric.py | 14 ++++++++++++-- dbt_semantic_interfaces/type_enums/__init__.py | 1 + dbt_semantic_interfaces/type_enums/period_agg.py | 9 +++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 dbt_semantic_interfaces/type_enums/period_agg.py diff --git a/dbt_semantic_interfaces/implementations/metric.py b/dbt_semantic_interfaces/implementations/metric.py index 17b8a6ff..72a2610d 100644 --- a/dbt_semantic_interfaces/implementations/metric.py +++ b/dbt_semantic_interfaces/implementations/metric.py @@ -21,6 +21,7 @@ from dbt_semantic_interfaces.type_enums import ( ConversionCalculationType, MetricType, + PeriodAggregation, TimeGranularity, ) from dsi_pydantic_shim import Field @@ -158,6 +159,14 @@ class PydanticConversionTypeParams(HashableBaseModel): constant_properties: Optional[List[PydanticConstantPropertyInput]] +class PydanticCumulativeTypeParams(HashableBaseModel): + """Type params to provide context for cumulative metrics properties.""" + + window: Optional[PydanticMetricTimeWindow] + grain_to_date: Optional[TimeGranularity] + period_agg: Optional[PeriodAggregation] = PeriodAggregation.START + + class PydanticMetricTypeParams(HashableBaseModel): """Type params add additional context to certain metric types (the context depends on the metric type).""" @@ -165,10 +174,11 @@ class PydanticMetricTypeParams(HashableBaseModel): numerator: Optional[PydanticMetricInput] denominator: Optional[PydanticMetricInput] expr: Optional[str] - window: Optional[PydanticMetricTimeWindow] - grain_to_date: Optional[TimeGranularity] + window: Optional[PydanticMetricTimeWindow] # warn if set + grain_to_date: Optional[TimeGranularity] # warn if set metrics: Optional[List[PydanticMetricInput]] conversion_type_params: Optional[PydanticConversionTypeParams] + cumulative_type_params: Optional[PydanticCumulativeTypeParams] input_measures: List[PydanticMetricInputMeasure] = Field(default_factory=list) diff --git a/dbt_semantic_interfaces/type_enums/__init__.py b/dbt_semantic_interfaces/type_enums/__init__.py index 0389d2c4..d0af35fc 100644 --- a/dbt_semantic_interfaces/type_enums/__init__.py +++ b/dbt_semantic_interfaces/type_enums/__init__.py @@ -7,6 +7,7 @@ from dbt_semantic_interfaces.type_enums.dimension_type import DimensionType # noqa:F401 from dbt_semantic_interfaces.type_enums.entity_type import EntityType # noqa:F401 from dbt_semantic_interfaces.type_enums.metric_type import MetricType # noqa:F401 +from dbt_semantic_interfaces.type_enums.period_agg import PeriodAggregation # noqa:F401 from dbt_semantic_interfaces.type_enums.semantic_manifest_node_type import ( # noqa:F401 SemanticManifestNodeType, ) diff --git a/dbt_semantic_interfaces/type_enums/period_agg.py b/dbt_semantic_interfaces/type_enums/period_agg.py new file mode 100644 index 00000000..24b8a5f1 --- /dev/null +++ b/dbt_semantic_interfaces/type_enums/period_agg.py @@ -0,0 +1,9 @@ +from dbt_semantic_interfaces.enum_extension import ExtendedEnum + + +class PeriodAggregation(ExtendedEnum): + """Options for how to aggregate across a time period.""" + + START = "start" + END = "end" + AVERAGE = "average"