diff --git a/metricflow-semantics/metricflow_semantics/specs/dunder_column_association_resolver.py b/metricflow-semantics/metricflow_semantics/specs/dunder_column_association_resolver.py index 3473618c74..8f2fead24b 100644 --- a/metricflow-semantics/metricflow_semantics/specs/dunder_column_association_resolver.py +++ b/metricflow-semantics/metricflow_semantics/specs/dunder_column_association_resolver.py @@ -1,6 +1,5 @@ from __future__ import annotations -from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup from metricflow_semantics.naming.linkable_spec_name import DUNDER from metricflow_semantics.specs.column_assoc import ( ColumnAssociation, @@ -28,8 +27,8 @@ class DunderColumnAssociationResolver(ColumnAssociationResolver): listing__country """ - def __init__(self, semantic_manifest_lookup: SemanticManifestLookup) -> None: # noqa: D107 - self._visitor_helper = DunderColumnAssociationResolverVisitor(semantic_manifest_lookup) + def __init__(self) -> None: # noqa: D107 + self._visitor_helper = DunderColumnAssociationResolverVisitor() def resolve_spec(self, spec: InstanceSpec) -> ColumnAssociation: # noqa: D102 return spec.accept(self._visitor_helper) @@ -38,9 +37,6 @@ def resolve_spec(self, spec: InstanceSpec) -> ColumnAssociation: # noqa: D102 class DunderColumnAssociationResolverVisitor(InstanceSpecVisitor[ColumnAssociation]): """Visitor helper class for DefaultColumnAssociationResolver2.""" - def __init__(self, semantic_manifest_lookup: SemanticManifestLookup) -> None: # noqa: D107 - self._semantic_manifest_lookup = semantic_manifest_lookup - def visit_metric_spec(self, metric_spec: MetricSpec) -> ColumnAssociation: # noqa: D102 return ColumnAssociation(metric_spec.element_name if metric_spec.alias is None else metric_spec.alias) diff --git a/metricflow-semantics/tests_metricflow_semantics/fixtures/manifest_fixtures.py b/metricflow-semantics/tests_metricflow_semantics/fixtures/manifest_fixtures.py index 00964fc8da..401a2680c9 100644 --- a/metricflow-semantics/tests_metricflow_semantics/fixtures/manifest_fixtures.py +++ b/metricflow-semantics/tests_metricflow_semantics/fixtures/manifest_fixtures.py @@ -137,7 +137,7 @@ def cyclic_join_semantic_manifest_lookup( # noqa: D103 def column_association_resolver( # noqa: D103 simple_semantic_manifest_lookup: SemanticManifestLookup, ) -> ColumnAssociationResolver: - return DunderColumnAssociationResolver(simple_semantic_manifest_lookup) + return DunderColumnAssociationResolver() @pytest.fixture(scope="session") diff --git a/metricflow/engine/metricflow_engine.py b/metricflow/engine/metricflow_engine.py index b4343c527d..9d490a4cdb 100644 --- a/metricflow/engine/metricflow_engine.py +++ b/metricflow/engine/metricflow_engine.py @@ -364,9 +364,7 @@ def __init__( SequentialIdGenerator.reset(MetricFlowEngine._ID_ENUMERATION_START_VALUE_FOR_INITIALIZER) self._semantic_manifest_lookup = semantic_manifest_lookup self._sql_client = sql_client - self._column_association_resolver = column_association_resolver or ( - DunderColumnAssociationResolver(semantic_manifest_lookup) - ) + self._column_association_resolver = column_association_resolver or (DunderColumnAssociationResolver()) self._time_source = time_source self._time_spine_sources = TimeSpineSource.build_standard_time_spine_sources( semantic_manifest_lookup.semantic_manifest @@ -463,12 +461,14 @@ def _create_execution_plan(self, mf_query_request: MetricFlowQueryRequest) -> Me raise InvalidQueryException("Group by items can't be specified with a saved query.") query_spec = self._query_parser.parse_and_validate_saved_query( saved_query_parameter=SavedQueryParameter(mf_query_request.saved_query_name), - where_filters=[ - PydanticWhereFilter(where_sql_template=where_constraint) - for where_constraint in mf_query_request.where_constraints - ] - if mf_query_request.where_constraints is not None - else None, + where_filters=( + [ + PydanticWhereFilter(where_sql_template=where_constraint) + for where_constraint in mf_query_request.where_constraints + ] + if mf_query_request.where_constraints is not None + else None + ), limit=mf_query_request.limit, time_constraint_start=mf_query_request.time_constraint_start, time_constraint_end=mf_query_request.time_constraint_end, diff --git a/metricflow/validation/data_warehouse_model_validator.py b/metricflow/validation/data_warehouse_model_validator.py index 95efadcb3e..b24afc187d 100644 --- a/metricflow/validation/data_warehouse_model_validator.py +++ b/metricflow/validation/data_warehouse_model_validator.py @@ -63,20 +63,16 @@ class QueryRenderingTools: def __init__(self, manifest: SemanticManifest) -> None: # noqa: D107 self.semantic_manifest_lookup = SemanticManifestLookup(semantic_manifest=manifest) self.source_node_builder = SourceNodeBuilder( - column_association_resolver=DunderColumnAssociationResolver(self.semantic_manifest_lookup), + column_association_resolver=DunderColumnAssociationResolver(), semantic_manifest_lookup=self.semantic_manifest_lookup, ) - self.converter = SemanticModelToDataSetConverter( - column_association_resolver=DunderColumnAssociationResolver( - semantic_manifest_lookup=self.semantic_manifest_lookup - ) - ) + self.converter = SemanticModelToDataSetConverter(column_association_resolver=DunderColumnAssociationResolver()) self.plan_converter = DataflowToSqlQueryPlanConverter( - column_association_resolver=DunderColumnAssociationResolver(self.semantic_manifest_lookup), + column_association_resolver=DunderColumnAssociationResolver(), semantic_manifest_lookup=self.semantic_manifest_lookup, ) self.node_resolver = DataflowPlanNodeOutputDataSetResolver( - column_association_resolver=DunderColumnAssociationResolver(self.semantic_manifest_lookup), + column_association_resolver=DunderColumnAssociationResolver(), semantic_manifest_lookup=self.semantic_manifest_lookup, ) diff --git a/scripts/ci_tests/metricflow_package_test.py b/scripts/ci_tests/metricflow_package_test.py index 81e055c24d..7a25559108 100644 --- a/scripts/ci_tests/metricflow_package_test.py +++ b/scripts/ci_tests/metricflow_package_test.py @@ -64,9 +64,7 @@ def _create_data_sets( semantic_models: Sequence[SemanticModel] = semantic_manifest_lookup.semantic_manifest.semantic_models semantic_models = sorted(semantic_models, key=lambda x: x.name) - converter = SemanticModelToDataSetConverter( - column_association_resolver=DunderColumnAssociationResolver(semantic_manifest_lookup) - ) + converter = SemanticModelToDataSetConverter(column_association_resolver=DunderColumnAssociationResolver()) for semantic_model in semantic_models: data_sets[semantic_model.name] = converter.create_sql_source_data_set(semantic_model) @@ -138,7 +136,7 @@ def log_dataflow_plan() -> None: # noqa: D103 semantic_manifest = _semantic_manifest() semantic_manifest_lookup = SemanticManifestLookup(semantic_manifest) data_set_mapping = _create_data_sets(semantic_manifest_lookup) - column_association_resolver = DunderColumnAssociationResolver(semantic_manifest_lookup) + column_association_resolver = DunderColumnAssociationResolver() source_node_builder = SourceNodeBuilder(column_association_resolver, semantic_manifest_lookup) source_node_set = source_node_builder.create_from_data_sets(list(data_set_mapping.values())) diff --git a/tests_metricflow/dataflow/builder/test_node_data_set.py b/tests_metricflow/dataflow/builder/test_node_data_set.py index 5e369b3386..5f7238cbd3 100644 --- a/tests_metricflow/dataflow/builder/test_node_data_set.py +++ b/tests_metricflow/dataflow/builder/test_node_data_set.py @@ -43,7 +43,7 @@ def test_no_parent_node_data_set( ) -> None: """Tests getting the data set from a single node.""" resolver: DataflowPlanNodeOutputDataSetResolver = DataflowPlanNodeOutputDataSetResolver( - column_association_resolver=DunderColumnAssociationResolver(simple_semantic_manifest_lookup), + column_association_resolver=DunderColumnAssociationResolver(), semantic_manifest_lookup=simple_semantic_manifest_lookup, ) @@ -96,7 +96,7 @@ def test_joined_node_data_set( ) -> None: """Tests getting the data set from a dataflow plan with a join.""" resolver: DataflowPlanNodeOutputDataSetResolver = DataflowPlanNodeOutputDataSetResolver( - column_association_resolver=DunderColumnAssociationResolver(simple_semantic_manifest_lookup), + column_association_resolver=DunderColumnAssociationResolver(), semantic_manifest_lookup=simple_semantic_manifest_lookup, ) diff --git a/tests_metricflow/dataflow/builder/test_node_evaluator.py b/tests_metricflow/dataflow/builder/test_node_evaluator.py index f4785806e4..d559973615 100644 --- a/tests_metricflow/dataflow/builder/test_node_evaluator.py +++ b/tests_metricflow/dataflow/builder/test_node_evaluator.py @@ -60,7 +60,7 @@ def make_multihop_node_evaluator( ) -> NodeEvaluatorForLinkableInstances: """Return a node evaluator using the nodes in multihop_semantic_model_name_to_nodes.""" node_data_set_resolver: DataflowPlanNodeOutputDataSetResolver = DataflowPlanNodeOutputDataSetResolver( - column_association_resolver=DunderColumnAssociationResolver(semantic_manifest_lookup_with_multihop_links), + column_association_resolver=DunderColumnAssociationResolver(), semantic_manifest_lookup=semantic_manifest_lookup_with_multihop_links, ) @@ -510,7 +510,7 @@ def test_node_evaluator_with_scd_target( ) -> None: """Tests the case where the joined node is an SCD with a validity window filter.""" node_data_set_resolver: DataflowPlanNodeOutputDataSetResolver = DataflowPlanNodeOutputDataSetResolver( - column_association_resolver=DunderColumnAssociationResolver(scd_semantic_manifest_lookup), + column_association_resolver=DunderColumnAssociationResolver(), semantic_manifest_lookup=scd_semantic_manifest_lookup, ) diff --git a/tests_metricflow/examples/test_node_sql.py b/tests_metricflow/examples/test_node_sql.py index d0a0f281cb..3e43f885d6 100644 --- a/tests_metricflow/examples/test_node_sql.py +++ b/tests_metricflow/examples/test_node_sql.py @@ -35,13 +35,11 @@ def test_view_sql_generated_at_a_node( SemanticModelReference(semantic_model_name="bookings_source") ) assert bookings_semantic_model - column_association_resolver = DunderColumnAssociationResolver( - semantic_manifest_lookup=simple_semantic_manifest_lookup, - ) + column_association_resolver = DunderColumnAssociationResolver() to_data_set_converter = SemanticModelToDataSetConverter(column_association_resolver) to_sql_plan_converter = DataflowToSqlQueryPlanConverter( - column_association_resolver=DunderColumnAssociationResolver(simple_semantic_manifest_lookup), + column_association_resolver=DunderColumnAssociationResolver(), semantic_manifest_lookup=simple_semantic_manifest_lookup, ) sql_renderer: SqlQueryPlanRenderer = sql_client.sql_query_plan_renderer diff --git a/tests_metricflow/fixtures/manifest_fixtures.py b/tests_metricflow/fixtures/manifest_fixtures.py index d5f2026b1e..8c00673c13 100644 --- a/tests_metricflow/fixtures/manifest_fixtures.py +++ b/tests_metricflow/fixtures/manifest_fixtures.py @@ -169,7 +169,7 @@ def from_parameters( # noqa: D102 semantic_manifest_lookup = SemanticManifestLookup(semantic_manifest) data_set_mapping = MetricFlowEngineTestFixture._create_data_sets(semantic_manifest_lookup) read_node_mapping = MetricFlowEngineTestFixture._data_set_to_read_nodes(data_set_mapping) - column_association_resolver = DunderColumnAssociationResolver(semantic_manifest_lookup) + column_association_resolver = DunderColumnAssociationResolver() source_node_builder = SourceNodeBuilder(column_association_resolver, semantic_manifest_lookup) source_node_set = source_node_builder.create_from_data_sets(list(data_set_mapping.values())) node_output_resolver = DataflowPlanNodeOutputDataSetResolver( @@ -247,9 +247,7 @@ def _create_data_sets( semantic_models: Sequence[SemanticModel] = semantic_manifest_lookup.semantic_manifest.semantic_models semantic_models = sorted(semantic_models, key=lambda x: x.name) - converter = SemanticModelToDataSetConverter( - column_association_resolver=DunderColumnAssociationResolver(semantic_manifest_lookup) - ) + converter = SemanticModelToDataSetConverter(column_association_resolver=DunderColumnAssociationResolver()) for semantic_model in semantic_models: data_sets[semantic_model.name] = converter.create_sql_source_data_set(semantic_model) diff --git a/tests_metricflow/integration/conftest.py b/tests_metricflow/integration/conftest.py index 5c0da3bdb1..b546dbac51 100644 --- a/tests_metricflow/integration/conftest.py +++ b/tests_metricflow/integration/conftest.py @@ -38,9 +38,7 @@ def it_helpers( # noqa: D103 mf_engine=MetricFlowEngine( semantic_manifest_lookup=simple_semantic_manifest_lookup, sql_client=sql_client, - column_association_resolver=DunderColumnAssociationResolver( - semantic_manifest_lookup=simple_semantic_manifest_lookup - ), + column_association_resolver=DunderColumnAssociationResolver(), time_source=ConfigurableTimeSource(as_datetime("2020-01-01")), ), mf_system_schema=mf_test_configuration.mf_system_schema, diff --git a/tests_metricflow/integration/test_rendered_query.py b/tests_metricflow/integration/test_rendered_query.py index 7bc004a0d5..f940448477 100644 --- a/tests_metricflow/integration/test_rendered_query.py +++ b/tests_metricflow/integration/test_rendered_query.py @@ -46,9 +46,7 @@ def test_id_enumeration( # noqa: D103 mf_engine = MetricFlowEngine( semantic_manifest_lookup=simple_semantic_manifest_lookup, sql_client=sql_client, - column_association_resolver=DunderColumnAssociationResolver( - semantic_manifest_lookup=simple_semantic_manifest_lookup - ), + column_association_resolver=DunderColumnAssociationResolver(), time_source=ConfigurableTimeSource(as_datetime("2020-01-01")), consistent_id_enumeration=True, ) diff --git a/tests_metricflow/plan_conversion/instance_converters/test_create_select_columns_with_measures_aggregated.py b/tests_metricflow/plan_conversion/instance_converters/test_create_select_columns_with_measures_aggregated.py index 1c188dffe2..28d177829a 100644 --- a/tests_metricflow/plan_conversion/instance_converters/test_create_select_columns_with_measures_aggregated.py +++ b/tests_metricflow/plan_conversion/instance_converters/test_create_select_columns_with_measures_aggregated.py @@ -49,7 +49,7 @@ def test_sum_aggregation( select_column_set: SelectColumnSet = CreateSelectColumnsWithMeasuresAggregated( __SOURCE_TABLE_ALIAS, - DunderColumnAssociationResolver(simple_semantic_manifest_lookup), + DunderColumnAssociationResolver(), simple_semantic_manifest_lookup.semantic_model_lookup, (MetricInputMeasureSpec(measure_spec=MeasureSpec(element_name="booking_value")),), ).transform(instance_set=instance_set) @@ -71,7 +71,7 @@ def test_sum_boolean_aggregation( select_column_set: SelectColumnSet = CreateSelectColumnsWithMeasuresAggregated( __SOURCE_TABLE_ALIAS, - DunderColumnAssociationResolver(simple_semantic_manifest_lookup), + DunderColumnAssociationResolver(), simple_semantic_manifest_lookup.semantic_model_lookup, (MetricInputMeasureSpec(measure_spec=MeasureSpec(element_name="instant_bookings")),), ).transform(instance_set=instance_set) @@ -94,7 +94,7 @@ def test_avg_aggregation( select_column_set: SelectColumnSet = CreateSelectColumnsWithMeasuresAggregated( __SOURCE_TABLE_ALIAS, - DunderColumnAssociationResolver(simple_semantic_manifest_lookup), + DunderColumnAssociationResolver(), simple_semantic_manifest_lookup.semantic_model_lookup, (MetricInputMeasureSpec(measure_spec=MeasureSpec(element_name="average_booking_value")),), ).transform(instance_set=instance_set) @@ -116,7 +116,7 @@ def test_count_distinct_aggregation( select_column_set: SelectColumnSet = CreateSelectColumnsWithMeasuresAggregated( __SOURCE_TABLE_ALIAS, - DunderColumnAssociationResolver(simple_semantic_manifest_lookup), + DunderColumnAssociationResolver(), simple_semantic_manifest_lookup.semantic_model_lookup, (MetricInputMeasureSpec(measure_spec=MeasureSpec(element_name="bookers")),), ).transform(instance_set=instance_set) @@ -138,7 +138,7 @@ def test_max_aggregation( select_column_set: SelectColumnSet = CreateSelectColumnsWithMeasuresAggregated( __SOURCE_TABLE_ALIAS, - DunderColumnAssociationResolver(simple_semantic_manifest_lookup), + DunderColumnAssociationResolver(), simple_semantic_manifest_lookup.semantic_model_lookup, (MetricInputMeasureSpec(measure_spec=MeasureSpec(element_name="largest_listing")),), ).transform(instance_set=instance_set) @@ -160,7 +160,7 @@ def test_min_aggregation( select_column_set: SelectColumnSet = CreateSelectColumnsWithMeasuresAggregated( __SOURCE_TABLE_ALIAS, - DunderColumnAssociationResolver(simple_semantic_manifest_lookup), + DunderColumnAssociationResolver(), simple_semantic_manifest_lookup.semantic_model_lookup, (MetricInputMeasureSpec(measure_spec=MeasureSpec(element_name="smallest_listing")),), ).transform(instance_set=instance_set) @@ -182,7 +182,7 @@ def test_aliased_sum( select_column_set: SelectColumnSet = CreateSelectColumnsWithMeasuresAggregated( __SOURCE_TABLE_ALIAS, - DunderColumnAssociationResolver(simple_semantic_manifest_lookup), + DunderColumnAssociationResolver(), simple_semantic_manifest_lookup.semantic_model_lookup, (MetricInputMeasureSpec(measure_spec=MeasureSpec(element_name="booking_value"), alias="bvalue"),), ).transform(instance_set=instance_set) @@ -205,7 +205,7 @@ def test_percentile_aggregation( select_column_set: SelectColumnSet = CreateSelectColumnsWithMeasuresAggregated( __SOURCE_TABLE_ALIAS, - DunderColumnAssociationResolver(simple_semantic_manifest_lookup), + DunderColumnAssociationResolver(), simple_semantic_manifest_lookup.semantic_model_lookup, (MetricInputMeasureSpec(measure_spec=MeasureSpec(element_name="booking_value_p99")),), ).transform(instance_set=instance_set) diff --git a/tests_metricflow/plan_conversion/test_dataflow_to_execution.py b/tests_metricflow/plan_conversion/test_dataflow_to_execution.py index 08db7d27e0..cd5425e7d4 100644 --- a/tests_metricflow/plan_conversion/test_dataflow_to_execution.py +++ b/tests_metricflow/plan_conversion/test_dataflow_to_execution.py @@ -26,7 +26,7 @@ def make_execution_plan_converter( # noqa: D103 ) -> DataflowToExecutionPlanConverter: return DataflowToExecutionPlanConverter( sql_plan_converter=DataflowToSqlQueryPlanConverter( - column_association_resolver=DunderColumnAssociationResolver(semantic_manifest_lookup), + column_association_resolver=DunderColumnAssociationResolver(), semantic_manifest_lookup=semantic_manifest_lookup, ), sql_plan_renderer=DefaultSqlQueryPlanRenderer(),