diff --git a/metricflow-semantics/metricflow_semantics/protocols/query_parameter.py b/metricflow-semantics/metricflow_semantics/protocols/query_parameter.py index e223966618..2407ba8ac9 100644 --- a/metricflow-semantics/metricflow_semantics/protocols/query_parameter.py +++ b/metricflow-semantics/metricflow_semantics/protocols/query_parameter.py @@ -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: diff --git a/metricflow-semantics/metricflow_semantics/query/query_resolver.py b/metricflow-semantics/metricflow_semantics/query/query_resolver.py index 76eb0a57e0..e00dc8dc4d 100644 --- a/metricflow-semantics/metricflow_semantics/query/query_resolver.py +++ b/metricflow-semantics/metricflow_semantics/query/query_resolver.py @@ -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, ) @@ -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( diff --git a/metricflow-semantics/metricflow_semantics/specs/query_param_implementations.py b/metricflow-semantics/metricflow_semantics/specs/query_param_implementations.py index 9715ddbf00..e6d461176f 100644 --- a/metricflow-semantics/metricflow_semantics/specs/query_param_implementations.py +++ b/metricflow-semantics/metricflow_semantics/specs/query_param_implementations.py @@ -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: