From bec5255b7cfbd3eb470ca78c4f9366d272862750 Mon Sep 17 00:00:00 2001 From: Will Deng Date: Mon, 11 Nov 2024 16:37:57 -0500 Subject: [PATCH] Updated StructuredLinkableSpecName and removed DunderedNameFormatter --- .../metricflow_semantics/naming/dunder_scheme.py | 2 +- .../specs/where_filter/where_filter_dimension.py | 12 +++++++++--- .../specs/where_filter/where_filter_entity.py | 8 +++++--- .../specs/where_filter/where_filter_transform.py | 1 + 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/naming/dunder_scheme.py b/metricflow-semantics/metricflow_semantics/naming/dunder_scheme.py index df3e66879e..926adbccc1 100644 --- a/metricflow-semantics/metricflow_semantics/naming/dunder_scheme.py +++ b/metricflow-semantics/metricflow_semantics/naming/dunder_scheme.py @@ -23,7 +23,7 @@ class DunderNamingScheme(QueryItemNamingScheme): """A naming scheme using the dundered name syntax. - TODO: Consolidate with StructuredLinkableSpecName / DunderedNameFormatter. + TODO: Consolidate with StructuredLinkableSpecName. """ _INPUT_REGEX = re.compile(r"\A[a-z]([a-z0-9_])*[a-z0-9]\Z") 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 9ca2798a61..521e5e2b33 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 @@ -7,7 +7,6 @@ DimensionCallParameterSet, TimeDimensionCallParameterSet, ) -from dbt_semantic_interfaces.naming.dundered import DunderedNameFormatter from dbt_semantic_interfaces.protocols.protocol_hint import ProtocolHint from dbt_semantic_interfaces.protocols.query_interface import ( QueryInterfaceDimension, @@ -18,6 +17,7 @@ from typing_extensions import override from metricflow_semantics.errors.error_classes import InvalidQuerySyntax +from metricflow_semantics.naming.linkable_spec_name import StructuredLinkableSpecName from metricflow_semantics.query.group_by_item.filter_spec_resolution.filter_location import WhereFilterLocation from metricflow_semantics.query.group_by_item.filter_spec_resolution.filter_spec_lookup import ( FilterSpecResolutionLookUp, @@ -134,15 +134,19 @@ def __init__( # noqa spec_resolution_lookup: FilterSpecResolutionLookUp, where_filter_location: WhereFilterLocation, rendered_spec_tracker: RenderedSpecTracker, + custom_granularity_names: Sequence[str], ): self._column_association_resolver = column_association_resolver self._resolved_spec_lookup = spec_resolution_lookup self._where_filter_location = where_filter_location self._rendered_spec_tracker = rendered_spec_tracker + self._custom_granularity_names = custom_granularity_names def create(self, name: str, entity_path: Sequence[str] = ()) -> WhereFilterDimension: """Create a WhereFilterDimension.""" - structured_name = DunderedNameFormatter.parse_name(name.lower()) + structured_name = StructuredLinkableSpecName.from_name( + name.lower(), custom_granularity_names=self._custom_granularity_names + ) return WhereFilterDimension( column_association_resolver=self._column_association_resolver, @@ -151,5 +155,7 @@ 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) - + structured_name.entity_links, + + tuple( + EntityReference(entity_link_name.lower()) for entity_link_name in structured_name.entity_link_names + ), ) 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 080beabfcd..098391f908 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 @@ -5,7 +5,6 @@ from dbt_semantic_interfaces.call_parameter_sets import ( EntityCallParameterSet, ) -from dbt_semantic_interfaces.naming.dundered import DunderedNameFormatter from dbt_semantic_interfaces.protocols.protocol_hint import ProtocolHint from dbt_semantic_interfaces.protocols.query_interface import QueryInterfaceEntity, QueryInterfaceEntityFactory from dbt_semantic_interfaces.references import EntityReference @@ -14,6 +13,7 @@ from typing_extensions import override from metricflow_semantics.errors.error_classes import InvalidQuerySyntax +from metricflow_semantics.naming.linkable_spec_name import StructuredLinkableSpecName from metricflow_semantics.query.group_by_item.filter_spec_resolution.filter_location import WhereFilterLocation from metricflow_semantics.query.group_by_item.filter_spec_resolution.filter_spec_lookup import ( FilterSpecResolutionLookUp, @@ -103,7 +103,7 @@ def __init__( # noqa def create(self, entity_name: str, entity_path: Sequence[str] = ()) -> WhereFilterEntity: """Create a WhereFilterEntity.""" - structured_name = DunderedNameFormatter.parse_name(entity_name.lower()) + structured_name = StructuredLinkableSpecName.from_name(entity_name.lower(), custom_granularity_names=()) return WhereFilterEntity( column_association_resolver=self._column_association_resolver, @@ -112,5 +112,7 @@ 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) - + structured_name.entity_links, + + tuple( + EntityReference(entity_link_name.lower()) for entity_link_name in structured_name.entity_link_names + ), ) diff --git a/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_transform.py b/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_transform.py index 47ef06476d..7397f7b4d7 100644 --- a/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_transform.py +++ b/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_transform.py @@ -70,6 +70,7 @@ def create_from_where_filter_intersection( # noqa: D102 spec_resolution_lookup=self._spec_resolution_lookup, where_filter_location=filter_location, rendered_spec_tracker=rendered_spec_tracker, + custom_granularity_names=self._semantic_model_lookup.custom_granularity_names, ) time_dimension_factory = WhereFilterTimeDimensionFactory( column_association_resolver=self._column_association_resolver,