From 077c7692235a8a099c9760ef3d9186a4c1d73ad3 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Mon, 6 May 2024 20:52:05 -0700 Subject: [PATCH] PR feedback --- .../model/semantics/linkable_element.py | 9 ++++----- .../model/semantics/linkable_spec_resolver.py | 2 +- .../model/semantics/test_linkable_element_set.py | 8 ++++---- .../model/test_where_filter_spec.py | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/model/semantics/linkable_element.py b/metricflow-semantics/metricflow_semantics/model/semantics/linkable_element.py index 9e8e82d4b5..05d02a204c 100644 --- a/metricflow-semantics/metricflow_semantics/model/semantics/linkable_element.py +++ b/metricflow-semantics/metricflow_semantics/model/semantics/linkable_element.py @@ -219,9 +219,7 @@ def derived_from_semantic_models(self) -> Sequence[SemanticModelReference]: Includes semantic models used in the join paths for both the inner and outer queries (if applicable), plus the semantic models the metric's measure(s) originated from. """ - semantic_model_references = set( - self.join_path.metric_subquery_join_path_element.metric_derived_from_semantic_models - ) + semantic_model_references = set(self.join_path.metric_subquery_join_path_element.derived_from_semantic_models) if self.join_path.semantic_model_join_path: semantic_model_references.update(self.join_path.semantic_model_join_path.derived_from_semantic_models) if self.metric_to_entity_join_path: @@ -301,6 +299,7 @@ class MetricSubqueryJoinPathElement: Args: metric_reference: The metric that's aggregated in the subquery. + derived_from_semantic_models: The semantic models that the measure's input metrics are defined in. join_on_entity: The entity that the metric is grouped by in the subquery. This will be updated in V2 to allow a list of entitites & dimensions. entity_links: Sequence of entities joined to get from a metric source to the `join_on_entity`. @@ -309,14 +308,14 @@ class MetricSubqueryJoinPathElement: """ metric_reference: MetricReference - metric_derived_from_semantic_models: Tuple[SemanticModelReference, ...] + derived_from_semantic_models: Tuple[SemanticModelReference, ...] join_on_entity: EntityReference entity_links: Tuple[EntityReference, ...] metric_to_entity_join_path: Optional[SemanticModelJoinPath] = None def __post_init__(self) -> None: # noqa: D105 assert ( - self.metric_derived_from_semantic_models + self.derived_from_semantic_models ), "There must be at least one semantic model from which the metric is derived." diff --git a/metricflow-semantics/metricflow_semantics/model/semantics/linkable_spec_resolver.py b/metricflow-semantics/metricflow_semantics/model/semantics/linkable_spec_resolver.py index 696d9438dc..b39a591843 100644 --- a/metricflow-semantics/metricflow_semantics/model/semantics/linkable_spec_resolver.py +++ b/metricflow-semantics/metricflow_semantics/model/semantics/linkable_spec_resolver.py @@ -200,7 +200,7 @@ def __init__( for linkable_entity in linkable_entities: metric_subquery_join_path_element = MetricSubqueryJoinPathElement( metric_reference=metric_reference, - metric_derived_from_semantic_models=defined_from_semantic_models, + derived_from_semantic_models=defined_from_semantic_models, join_on_entity=linkable_entity.reference, entity_links=linkable_entity.entity_links, metric_to_entity_join_path=( diff --git a/metricflow-semantics/tests_metricflow_semantics/model/semantics/test_linkable_element_set.py b/metricflow-semantics/tests_metricflow_semantics/model/semantics/test_linkable_element_set.py index bcea6e3bb5..624f3c5962 100644 --- a/metricflow-semantics/tests_metricflow_semantics/model/semantics/test_linkable_element_set.py +++ b/metricflow-semantics/tests_metricflow_semantics/model/semantics/test_linkable_element_set.py @@ -137,7 +137,7 @@ join_path=SemanticModelToMetricSubqueryJoinPath( metric_subquery_join_path_element=MetricSubqueryJoinPathElement( metric_reference=_base_metric_reference, - metric_derived_from_semantic_models=(_metric_semantic_model,), + derived_from_semantic_models=(_metric_semantic_model,), join_on_entity=_base_entity_reference, entity_links=(_base_entity_reference,), ), @@ -148,7 +148,7 @@ join_path=SemanticModelToMetricSubqueryJoinPath( metric_subquery_join_path_element=MetricSubqueryJoinPathElement( metric_reference=MetricReference(AMBIGUOUS_NAME), - metric_derived_from_semantic_models=(_metric_semantic_model,), + derived_from_semantic_models=(_metric_semantic_model,), join_on_entity=_base_entity_reference, entity_links=(_base_entity_reference,), ), @@ -160,7 +160,7 @@ join_path=SemanticModelToMetricSubqueryJoinPath( metric_subquery_join_path_element=MetricSubqueryJoinPathElement( metric_reference=MetricReference(AMBIGUOUS_NAME), - metric_derived_from_semantic_models=(_metric_semantic_model,), + derived_from_semantic_models=(_metric_semantic_model,), join_on_entity=_base_entity_reference, entity_links=(_base_entity_reference,), ), @@ -632,7 +632,7 @@ def linkable_set() -> LinkableElementSet: # noqa: D103 join_path=SemanticModelToMetricSubqueryJoinPath( metric_subquery_join_path_element=MetricSubqueryJoinPathElement( metric_reference=MetricReference("metric_element"), - metric_derived_from_semantic_models=(_metric_semantic_model,), + derived_from_semantic_models=(_metric_semantic_model,), join_on_entity=entity_3, entity_links=(entity_3, entity_4), metric_to_entity_join_path=SemanticModelJoinPath( diff --git a/metricflow-semantics/tests_metricflow_semantics/model/test_where_filter_spec.py b/metricflow-semantics/tests_metricflow_semantics/model/test_where_filter_spec.py index 09a82fb403..4d2557c8ab 100644 --- a/metricflow-semantics/tests_metricflow_semantics/model/test_where_filter_spec.py +++ b/metricflow-semantics/tests_metricflow_semantics/model/test_where_filter_spec.py @@ -536,7 +536,7 @@ def test_metric_in_filter( # noqa: D103 join_path=SemanticModelToMetricSubqueryJoinPath( metric_subquery_join_path_element=MetricSubqueryJoinPathElement( metric_reference=MetricReference("bookings"), - metric_derived_from_semantic_models=(SemanticModelReference("bookings"),), + derived_from_semantic_models=(SemanticModelReference("bookings"),), join_on_entity=EntityReference("listing"), entity_links=(EntityReference("listing"),), )