From 0bc036e719465411c4e1dbfd7828556fc38ec74d Mon Sep 17 00:00:00 2001 From: Will Deng Date: Tue, 12 Nov 2024 02:17:50 -0500 Subject: [PATCH] Add StructuredLinkableSpecName.entity_links property --- .../metricflow_semantics/naming/linkable_spec_name.py | 6 ++++++ .../specs/where_filter/where_filter_dimension.py | 4 +--- .../specs/where_filter/where_filter_entity.py | 4 +--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/naming/linkable_spec_name.py b/metricflow-semantics/metricflow_semantics/naming/linkable_spec_name.py index ecca286cc..1028c322f 100644 --- a/metricflow-semantics/metricflow_semantics/naming/linkable_spec_name.py +++ b/metricflow-semantics/metricflow_semantics/naming/linkable_spec_name.py @@ -4,6 +4,7 @@ from functools import lru_cache from typing import Optional, Sequence, Tuple +from dbt_semantic_interfaces.references import EntityReference from dbt_semantic_interfaces.type_enums.date_part import DatePart from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity @@ -106,6 +107,11 @@ def date_part_suffix(date_part: DatePart) -> str: """Suffix used for names with a date_part.""" return f"extract_{date_part.value}" + @property + def entity_links(self) -> Tuple[EntityReference, ...]: + """Returns the entity link references.""" + return tuple(EntityReference(entity_link_name.lower()) for entity_link_name in self.entity_link_names) + @property def granularity_free_qualified_name(self) -> str: """Renders the qualified name without the granularity suffix. diff --git a/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_dimension.py b/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_dimension.py index 521e5e2b3..409706178 100644 --- a/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_dimension.py +++ b/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_dimension.py @@ -155,7 +155,5 @@ def create(self, name: str, entity_path: Sequence[str] = ()) -> WhereFilterDimen rendered_spec_tracker=self._rendered_spec_tracker, element_name=structured_name.element_name, entity_links=tuple(EntityReference(entity_link_name.lower()) for entity_link_name in entity_path) - + tuple( - EntityReference(entity_link_name.lower()) for entity_link_name in structured_name.entity_link_names - ), + + structured_name.entity_links, ) diff --git a/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_entity.py b/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_entity.py index 098391f90..97f95f543 100644 --- a/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_entity.py +++ b/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_entity.py @@ -112,7 +112,5 @@ def create(self, entity_name: str, entity_path: Sequence[str] = ()) -> WhereFilt rendered_spec_tracker=self._rendered_spec_tracker, element_name=structured_name.element_name, entity_links=tuple(EntityReference(entity_link_name.lower()) for entity_link_name in entity_path) - + tuple( - EntityReference(entity_link_name.lower()) for entity_link_name in structured_name.entity_link_names - ), + + structured_name.entity_links, )