From 7d53ffd03fbceeab380488b22e8fd7b42d7658ae Mon Sep 17 00:00:00 2001 From: Will Deng Date: Wed, 15 Nov 2023 02:45:55 -0500 Subject: [PATCH] added missing method to MetricAccessor protocol --- metricflow/model/semantics/metric_lookup.py | 11 +++-------- metricflow/protocols/semantics.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/metricflow/model/semantics/metric_lookup.py b/metricflow/model/semantics/metric_lookup.py index f43348821d..b39ec0324e 100644 --- a/metricflow/model/semantics/metric_lookup.py +++ b/metricflow/model/semantics/metric_lookup.py @@ -106,14 +106,9 @@ def add_metric(self, metric: Metric) -> None: ) self._metrics[metric_reference] = metric - def configured_input_measure_for_metric(self, metric_reference: MetricReference) -> Optional[MetricInputMeasure]: - """Get input measure defined in the original metric config, if exists. - - When SemanticModel is constructed, input measures from input metrics are added to the list of input measures - for a metric. Here, use rules about metric types to determine which input measures were defined in the config: - - Simple & cumulative metrics require one input measure, and can't take any input metrics. - - Derived & ratio metrics take no input measures, only input metrics. - """ + def configured_input_measure_for_metric( # noqa: D + self, metric_reference: MetricReference + ) -> Optional[MetricInputMeasure]: metric = self.get_metric(metric_reference=metric_reference) if metric.type is MetricType.CUMULATIVE or metric.type is MetricType.SIMPLE: assert len(metric.input_measures) == 1, "Simple and cumulative metrics should have one input measure." diff --git a/metricflow/protocols/semantics.py b/metricflow/protocols/semantics.py index 6fc4e00a39..004a88324a 100644 --- a/metricflow/protocols/semantics.py +++ b/metricflow/protocols/semantics.py @@ -14,7 +14,7 @@ from dbt_semantic_interfaces.protocols.dimension import Dimension from dbt_semantic_interfaces.protocols.entity import Entity from dbt_semantic_interfaces.protocols.measure import Measure -from dbt_semantic_interfaces.protocols.metric import Metric +from dbt_semantic_interfaces.protocols.metric import Metric, MetricInputMeasure from dbt_semantic_interfaces.protocols.semantic_model import SemanticModel from dbt_semantic_interfaces.references import ( DimensionReference, @@ -187,3 +187,14 @@ def metric_input_specs_for_metric( ) -> Sequence[MetricSpec]: """Returns the metric input specs required to compute the metric.""" raise NotImplementedError + + @abstractmethod + def configured_input_measure_for_metric(self, metric_reference: MetricReference) -> Optional[MetricInputMeasure]: + """Get input measure defined in the original metric config, if exists. + + When SemanticModel is constructed, input measures from input metrics are added to the list of input measures + for a metric. Here, use rules about metric types to determine which input measures were defined in the config: + - Simple & cumulative metrics require one input measure, and can't take any input metrics. + - Derived & ratio metrics take no input measures, only input metrics. + """ + raise NotImplementedError