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 29, 2024
1 parent 82acea8 commit e2b616a
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions metricflow/model/semantics/linkable_spec_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,23 @@ 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 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,
)

@property
def reference(self) -> MetricReference: # noqa: D102
Expand Down Expand Up @@ -257,7 +272,9 @@ def intersection_by_path_key(linkable_element_sets: Sequence[LinkableElementSet]
for path_key, entities in join_path_to_linkable_entities.items()
},
path_key_to_linkable_metrics={
path_key: tuple(sorted(metrics, key=lambda linkable_metric: linkable_metric.element_name))
path_key: tuple(
sorted(metrics, key=lambda linkable_metric: linkable_metric.as_group_by_metric_spec.qualified_name)
)
for path_key, metrics in join_path_to_linkable_metrics.items()
},
)
Expand Down Expand Up @@ -355,11 +372,7 @@ def as_spec_set(self) -> LinkableSpecSet: # noqa: D102
for path_key in self.path_key_to_linkable_entities
),
group_by_metric_specs=tuple(
GroupByMetricSpec(
element_name=linkable_metric.element_name,
entity_links=linkable_metric.join_path.entity_links,
metric_subquery_entity_links=linkable_metric.metric_subquery_entity_links,
)
linkable_metric.as_group_by_metric_spec
for linkable_metrics in self.path_key_to_linkable_metrics.values()
for linkable_metric in linkable_metrics
),
Expand Down

0 comments on commit e2b616a

Please sign in to comment.