Skip to content

Commit

Permalink
Plumb metric alias from query interface to DataflowPlanBuilder
Browse files Browse the repository at this point in the history
This commit adds the necessary things to `MetricQueryParam` and to
the classes that build the query spec so that the alias information
reaches the `DataflowPlanBuilder`
  • Loading branch information
serramatutu committed Dec 13, 2024
1 parent cb8a4cc commit eea8707
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def name(self) -> str:
"""The name of the metric."""
raise NotImplementedError

@property
def alias(self) -> Optional[str]:
"""The alias of the metric."""
raise NotImplementedError

def query_resolver_input( # noqa: D102
self, semantic_manifest_lookup: SemanticManifestLookup
) -> ResolverInputForMetric:
Expand Down
13 changes: 13 additions & 0 deletions metricflow-semantics/metricflow_semantics/query/query_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from metricflow_semantics.model.semantic_model_derivation import SemanticModelDerivation
from metricflow_semantics.model.semantics.linkable_element_set import LinkableElementSet
from metricflow_semantics.naming.metric_scheme import MetricNamingScheme
from metricflow_semantics.protocols.query_parameter import MetricQueryParameter
from metricflow_semantics.query.group_by_item.filter_spec_resolution.filter_pattern_factory import (
WhereFilterPatternFactory,
)
Expand Down Expand Up @@ -196,6 +197,18 @@ def _resolve_metric_inputs(
)
)
else:
# Add the desired alias to the spec if it's provided in the input object
if (
isinstance(metric_input.input_obj, MetricQueryParameter)
and metric_input.input_obj.alias is not None
):
matching_specs = tuple(
MetricSpec(
element_name=ms.element_name,
alias=metric_input.input_obj.alias,
)
for ms in matching_specs
)
metric_specs.extend(matching_specs)

return ResolveMetricsResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class MetricParameter(ProtocolHint[MetricQueryParameter]):
"""Metric requested in a query."""

name: str
alias: Optional[str] = None

@override
def _implements_protocol(self) -> MetricQueryParameter:
Expand Down

0 comments on commit eea8707

Please sign in to comment.