From 952cc5ad0f85f0b37dfb0543add0959bbd893935 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 29 Aug 2024 13:19:49 -0700 Subject: [PATCH] Rename TimeSpineSource.create_from_manifest() to build_standard_time_spine_sources() This will help differentiate from a new method that builds custom time spine sources --- .../model/semantics/linkable_spec_resolver.py | 2 +- .../metricflow_semantics/time/time_spine_source.py | 4 +++- metricflow/dataflow/builder/source_node.py | 2 +- metricflow/engine/metricflow_engine.py | 4 +++- metricflow/plan_conversion/dataflow_to_sql.py | 4 +++- tests_metricflow/fixtures/table_fixtures.py | 6 +++--- tests_metricflow/plan_conversion/test_time_spine.py | 6 +++--- 7 files changed, 17 insertions(+), 11 deletions(-) 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 3afb0ea84a..5c3715197d 100644 --- a/metricflow-semantics/metricflow_semantics/model/semantics/linkable_spec_resolver.py +++ b/metricflow-semantics/metricflow_semantics/model/semantics/linkable_spec_resolver.py @@ -125,7 +125,7 @@ def __init__( # Sort semantic models by name for consistency in building derived objects. self._semantic_models = sorted(self._semantic_manifest.semantic_models, key=lambda x: x.name) self._join_evaluator = SemanticModelJoinEvaluator(semantic_model_lookup) - self._time_spine_sources = TimeSpineSource.create_from_manifest(self._semantic_manifest) + self._time_spine_sources = TimeSpineSource.build_standard_time_spine_sources(self._semantic_manifest) assert max_entity_links >= 0 self._max_entity_links = max_entity_links diff --git a/metricflow-semantics/metricflow_semantics/time/time_spine_source.py b/metricflow-semantics/metricflow_semantics/time/time_spine_source.py index 27655a5c00..2ac3471864 100644 --- a/metricflow-semantics/metricflow_semantics/time/time_spine_source.py +++ b/metricflow-semantics/metricflow_semantics/time/time_spine_source.py @@ -37,7 +37,9 @@ def spine_table(self) -> SqlTable: return SqlTable(schema_name=self.schema_name, table_name=self.table_name, db_name=self.db_name) @staticmethod - def create_from_manifest(semantic_manifest: SemanticManifest) -> Dict[TimeGranularity, TimeSpineSource]: + def build_standard_time_spine_sources( + semantic_manifest: SemanticManifest, + ) -> Dict[TimeGranularity, TimeSpineSource]: """Creates a time spine source based on what's in the manifest.""" time_spine_sources = { time_spine.primary_column.time_granularity: TimeSpineSource( diff --git a/metricflow/dataflow/builder/source_node.py b/metricflow/dataflow/builder/source_node.py index cf1fbcdd1c..9bd7af8a71 100644 --- a/metricflow/dataflow/builder/source_node.py +++ b/metricflow/dataflow/builder/source_node.py @@ -60,7 +60,7 @@ def __init__( # noqa: D107 self._semantic_manifest_lookup = semantic_manifest_lookup data_set_converter = SemanticModelToDataSetConverter(column_association_resolver) self._time_spine_source_nodes = {} - for granularity, time_spine_source in TimeSpineSource.create_from_manifest( + for granularity, time_spine_source in TimeSpineSource.build_standard_time_spine_sources( semantic_manifest_lookup.semantic_manifest ).items(): data_set = data_set_converter.build_time_spine_source_data_set(time_spine_source) diff --git a/metricflow/engine/metricflow_engine.py b/metricflow/engine/metricflow_engine.py index 0eedc652e1..685669cc4c 100644 --- a/metricflow/engine/metricflow_engine.py +++ b/metricflow/engine/metricflow_engine.py @@ -366,7 +366,9 @@ def __init__( DunderColumnAssociationResolver(semantic_manifest_lookup) ) self._time_source = time_source - self._time_spine_sources = TimeSpineSource.create_from_manifest(semantic_manifest_lookup.semantic_manifest) + self._time_spine_sources = TimeSpineSource.build_standard_time_spine_sources( + semantic_manifest_lookup.semantic_manifest + ) self._source_data_sets: List[SemanticModelDataSet] = [] converter = SemanticModelToDataSetConverter(column_association_resolver=self._column_association_resolver) for semantic_model in sorted( diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index ef2e437236..ffc00831be 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -195,7 +195,9 @@ def __init__( self._semantic_manifest_lookup = semantic_manifest_lookup self._metric_lookup = semantic_manifest_lookup.metric_lookup self._semantic_model_lookup = semantic_manifest_lookup.semantic_model_lookup - self._time_spine_sources = TimeSpineSource.create_from_manifest(semantic_manifest_lookup.semantic_manifest) + self._time_spine_sources = TimeSpineSource.build_standard_time_spine_sources( + semantic_manifest_lookup.semantic_manifest + ) @property def column_association_resolver(self) -> ColumnAssociationResolver: # noqa: D102 diff --git a/tests_metricflow/fixtures/table_fixtures.py b/tests_metricflow/fixtures/table_fixtures.py index f346ad70cc..2844178f21 100644 --- a/tests_metricflow/fixtures/table_fixtures.py +++ b/tests_metricflow/fixtures/table_fixtures.py @@ -42,9 +42,9 @@ def check_time_spine_source( The time spine table is defined in a table snapshot YAML file and is restored to the source schema based on that definition. The definition in the YAML should align with the definition in the time_spine_source fixture. """ - time_spine_source = TimeSpineSource.create_from_manifest(simple_semantic_manifest_lookup.semantic_manifest)[ - TimeGranularity.DAY - ] + time_spine_source = TimeSpineSource.build_standard_time_spine_sources( + simple_semantic_manifest_lookup.semantic_manifest + )[TimeGranularity.DAY] assert ( time_spine_source.schema_name == mf_test_configuration.mf_source_schema ), "The time spine source table should be in the source schema" diff --git a/tests_metricflow/plan_conversion/test_time_spine.py b/tests_metricflow/plan_conversion/test_time_spine.py index 178506aa39..968d57d42e 100644 --- a/tests_metricflow/plan_conversion/test_time_spine.py +++ b/tests_metricflow/plan_conversion/test_time_spine.py @@ -15,9 +15,9 @@ def test_date_spine_date_range( # noqa: D103 simple_semantic_manifest_lookup: SemanticManifestLookup, create_source_tables: None, ) -> None: - time_spine_source = TimeSpineSource.create_from_manifest(simple_semantic_manifest_lookup.semantic_manifest)[ - TimeGranularity.DAY - ] + time_spine_source = TimeSpineSource.build_standard_time_spine_sources( + simple_semantic_manifest_lookup.semantic_manifest + )[TimeGranularity.DAY] range_df = sql_client.query( textwrap.dedent( f"""\