Skip to content

Commit

Permalink
Add helper method SemanticModelJoinPath.from_single_element()
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Apr 30, 2024
1 parent f54eeed commit b7ff2c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,17 @@ def last_entity_link(self) -> EntityReference: # noqa: D102
@property
def entity_links(self) -> Tuple[EntityReference, ...]: # noqa: D102
return tuple(path_element.join_on_entity for path_element in self.path_elements)

@staticmethod
def from_single_element(
semantic_model_reference: SemanticModelReference, join_on_entity: EntityReference
) -> SemanticModelJoinPath:
"""Build SemanticModelJoinPath with just one join path element."""
return SemanticModelJoinPath(
path_elements=(
SemanticModelJoinPathElement(
semantic_model_reference=semantic_model_reference,
join_on_entity=join_on_entity,
),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,9 @@ def _get_joined_elements(self, measure_semantic_model: SemanticModel) -> Linkabl
if semantic_model.name == measure_semantic_model.name:
continue
join_paths.append(
SemanticModelJoinPath(
path_elements=(
SemanticModelJoinPathElement(
semantic_model_reference=semantic_model.reference,
join_on_entity=entity.reference,
),
)
SemanticModelJoinPath.from_single_element(
semantic_model_reference=semantic_model.reference,
join_on_entity=entity.reference,
)
)
single_hop_elements = LinkableElementSet.merge_by_path_key(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@
)
from metricflow_semantics.model.linkable_element_property import LinkableElementProperty
from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup
from metricflow_semantics.model.semantics.linkable_element import (
SemanticModelJoinPath,
SemanticModelJoinPathElement,
)
from metricflow_semantics.model.semantics.linkable_spec_resolver import (
ValidLinkableSpecResolver,
)
from metricflow_semantics.model.semantics.linkable_element import SemanticModelJoinPath
from metricflow_semantics.model.semantics.linkable_spec_resolver import ValidLinkableSpecResolver
from metricflow_semantics.model.semantics.semantic_model_join_evaluator import MAX_JOIN_HOPS
from metricflow_semantics.specs.spec_set import InstanceSpecSet
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration
Expand Down Expand Up @@ -147,13 +142,9 @@ def test_create_linkable_element_set_from_join_path( # noqa: D103
mf_test_configuration=mf_test_configuration,
set_id="result0",
linkable_element_set=simple_model_spec_resolver.create_linkable_element_set_from_join_path(
join_path=SemanticModelJoinPath(
path_elements=(
SemanticModelJoinPathElement(
semantic_model_reference=SemanticModelReference("listings_latest"),
join_on_entity=EntityReference("listing"),
),
)
join_path=SemanticModelJoinPath.from_single_element(
semantic_model_reference=SemanticModelReference("listings_latest"),
join_on_entity=EntityReference("listing"),
),
with_properties=frozenset({LinkableElementProperty.JOINED}),
),
Expand All @@ -170,13 +161,9 @@ def test_create_linkable_element_set_from_join_path_multi_hop( # noqa: D103
mf_test_configuration=mf_test_configuration,
set_id="result0",
linkable_element_set=simple_model_spec_resolver.create_linkable_element_set_from_join_path(
join_path=SemanticModelJoinPath(
path_elements=(
SemanticModelJoinPathElement(
semantic_model_reference=SemanticModelReference("listings_latest"),
join_on_entity=EntityReference("listing"),
),
)
join_path=SemanticModelJoinPath.from_single_element(
semantic_model_reference=SemanticModelReference("listings_latest"),
join_on_entity=EntityReference("listing"),
),
with_properties=frozenset({LinkableElementProperty.JOINED, LinkableElementProperty.MULTI_HOP}),
),
Expand Down

0 comments on commit b7ff2c0

Please sign in to comment.