Skip to content

Commit

Permalink
Use qualified name as ElementPathKey element name to ensure uniqueness
Browse files Browse the repository at this point in the history
There might be multiple linkable metrics available for a given metric_name + entity_links combo. This is because there might be multiple options for entity paths in the metric subquery, which is not accounted for here. Using the qualified name ensures we will have a unique ElementPathKey for each LinkableMetric.
  • Loading branch information
courtneyholcomb committed Apr 27, 2024
1 parent 82acea8 commit 6747f52
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions metricflow/model/semantics/linkable_spec_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,14 @@ def element_name(self) -> str: # noqa: D102
return self.reference.element_name

@property
def path_key(self) -> ElementPathKey: # noqa: D102
return ElementPathKey(element_name=self.element_name, entity_links=self.join_path.entity_links)
def path_key(self) -> ElementPathKey:
"""Key that can uniquely identify an element and the joins used to realize the element.
Use qualified name to guarantee uniqueness.
"""
return ElementPathKey(
element_name=self.as_group_by_metric_spec.qualified_name, entity_links=self.join_path.entity_links
)

@property
def reference(self) -> MetricReference: # noqa: D102
Expand All @@ -142,6 +148,15 @@ def metric_subquery_entity_links(self) -> Tuple[EntityReference, ...]:
metric_subquery = self.join_path.metric_subquery_join_path_element
return metric_subquery.entity_links + (metric_subquery.join_on_entity,)

@property
def as_group_by_metric_spec(self) -> GroupByMetricSpec:
"""Convert LinkableMetric to GroupByMetricSpec."""
return GroupByMetricSpec(
element_name=self.element_name,
entity_links=self.join_path.entity_links,
metric_subquery_entity_links=self.metric_subquery_entity_links,
)


@dataclass(frozen=True)
class LinkableElementSet:
Expand Down

0 comments on commit 6747f52

Please sign in to comment.