Skip to content

Commit

Permalink
fixup! Check when optimizing metric scans with similar aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
serramatutu committed Nov 4, 2024
1 parent 86fbfbd commit 1b7d1bc
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions metricflow/dataflow/nodes/compute_metrics.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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__()
Expand All @@ -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,
)

Expand Down Expand Up @@ -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, ""
Expand Down

0 comments on commit 1b7d1bc

Please sign in to comment.