Skip to content

Commit

Permalink
added missing method to MetricAccessor protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamDee committed Nov 15, 2023
1 parent 45a970d commit 7d53ffd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
11 changes: 3 additions & 8 deletions metricflow/model/semantics/metric_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
13 changes: 12 additions & 1 deletion metricflow/protocols/semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

0 comments on commit 7d53ffd

Please sign in to comment.