Skip to content

Commit

Permalink
Add tests for LinkableElementSet helper methods
Browse files Browse the repository at this point in the history
The LinkableElementSet has some helper methods to assist with certain
gnarly operations, but these are largely untested. Since tests are
the best documentation of behavior, we add some here.

This commit also includes some updates to documentation to clarify
behavior under certain common scenarios.
  • Loading branch information
tlento committed Apr 23, 2024
1 parent b1f728b commit 9ff7465
Show file tree
Hide file tree
Showing 2 changed files with 486 additions and 1 deletion.
10 changes: 9 additions & 1 deletion metricflow/model/semantics/linkable_element_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class LinkableElementSet:
def merge_by_path_key(linkable_element_sets: Sequence[LinkableElementSet]) -> LinkableElementSet:
"""Combine multiple sets together by the path key.
If there are elements with the same join key, those elements will be categorized as ambiguous.
If there are elements with the same join key and different element(s) in the tuple of values,
those elements will be categorized as ambiguous.
Note this does not deduplicate values, so there may be unambiguous merged sets that appear to have
multiple values if all one does is a simple length check.
"""
key_to_linkable_dimensions: Dict[ElementPathKey, List[LinkableDimension]] = defaultdict(list)
key_to_linkable_entities: Dict[ElementPathKey, List[LinkableEntity]] = defaultdict(list)
Expand Down Expand Up @@ -60,6 +63,11 @@ def merge_by_path_key(linkable_element_sets: Sequence[LinkableElementSet]) -> Li
def intersection_by_path_key(linkable_element_sets: Sequence[LinkableElementSet]) -> LinkableElementSet:
"""Find the intersection of all elements in the sets by path key.
This will return the intersection of all path keys defined in the sets, but the union of elements associated
with each path key. In other words, it filters out path keys (i.e., linkable specs) that are not referenced
in every set in the input sequence, but it preserves all of the various potentially ambiguous LinkableElement
instances associated with the path keys that remain.
This is useful to figure out the common dimensions that are possible to query with multiple metrics. You would
find the LinkableSpecSet for each metric in the query, then do an intersection of the sets.
"""
Expand Down
Loading

0 comments on commit 9ff7465

Please sign in to comment.