From 1b7d1bc9ba0488753322713ed9563965456d0895 Mon Sep 17 00:00:00 2001 From: serramatutu Date: Mon, 4 Nov 2024 16:16:08 +0100 Subject: [PATCH] fixup! Check when optimizing metric scans with similar aliases --- metricflow/dataflow/nodes/compute_metrics.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/metricflow/dataflow/nodes/compute_metrics.py b/metricflow/dataflow/nodes/compute_metrics.py index fead0ebdf..5241d6045 100644 --- a/metricflow/dataflow/nodes/compute_metrics.py +++ b/metricflow/dataflow/nodes/compute_metrics.py @@ -1,7 +1,7 @@ from __future__ import annotations -from dataclasses import dataclass, field -from typing import Dict, Sequence, Set, Tuple +from dataclasses import dataclass +from typing import Sequence, Set, Tuple from metricflow_semantics.dag.id_prefix import IdPrefix, StaticIdPrefix from metricflow_semantics.dag.mf_dag import DisplayedProperty @@ -28,7 +28,6 @@ class ComputeMetricsNode(DataflowPlanNode): metric_specs: Tuple[MetricSpec, ...] for_group_by_source_node: bool _aggregated_to_elements: Tuple[LinkableInstanceSpec, ...] - _alias_to_metric_spec: Dict[str, MetricSpec] = field(hash=False) def __post_init__(self) -> None: # noqa: D105 super().__post_init__() @@ -46,7 +45,6 @@ def create( # noqa: D102 parent_nodes=(parent_node,), metric_specs=tuple(metric_specs), _aggregated_to_elements=tuple(aggregated_to_elements), - _alias_to_metric_spec={spec.alias: spec for spec in metric_specs if spec.alias is not None}, for_group_by_source_node=for_group_by_source_node, ) @@ -100,15 +98,17 @@ def can_combine(self, other_node: ComputeMetricsNode) -> Tuple[bool, str]: if other_node.for_group_by_source_node != self.for_group_by_source_node: return False, "one node is a group by metric source node" + alias_to_metric_spec = {spec.alias: spec for spec in self.metric_specs if spec.alias is not None} + for spec in other_node.metric_specs: if ( spec.alias is not None - and spec.alias in self._alias_to_metric_spec - and self._alias_to_metric_spec[spec.alias] != spec + and spec.alias in alias_to_metric_spec + and alias_to_metric_spec[spec.alias] != spec ): return ( False, - f"'{spec.alias}' is defined in both nodes but it refers to different things in each of them", + f"Alias '{spec.alias}' is defined in both nodes but it refers to different things in each of them", ) return True, ""