From 91f9f08c4a9e13e761440e82ea438d8025c8c74a Mon Sep 17 00:00:00 2001 From: William Deng Date: Wed, 4 Jan 2023 23:14:45 -0500 Subject: [PATCH] fix test --- .../source_scan/test_source_scan_optimizer.py | 27 ++++++++++++++++--- .../test_dataflow_to_sql_plan.py | 19 ++++++++++++- ...constrained_metric_not_combined__dfp_0.xml | 24 ++++++++++++----- ...onstrained_metric_not_combined__dfpo_0.xml | 24 ++++++++++++----- 4 files changed, 76 insertions(+), 18 deletions(-) diff --git a/metricflow/test/dataflow/optimizer/source_scan/test_source_scan_optimizer.py b/metricflow/test/dataflow/optimizer/source_scan/test_source_scan_optimizer.py index 7e8b3e8346..34381238ad 100644 --- a/metricflow/test/dataflow/optimizer/source_scan/test_source_scan_optimizer.py +++ b/metricflow/test/dataflow/optimizer/source_scan/test_source_scan_optimizer.py @@ -33,11 +33,14 @@ from metricflow.dataset.data_source_adapter import DataSourceDataSet from metricflow.dataset.dataset import DataSet from metricflow.specs import ( - MetricFlowQuerySpec, - MetricSpec, DimensionSpec, IdentifierReference, + LinkableSpecSet, + MetricFlowQuerySpec, + MetricSpec, + SpecWhereClauseConstraint, ) +from metricflow.sql.sql_bind_parameters import SqlBindParameters from metricflow.test.dataflow_plan_to_svg import display_graph_if_requested from metricflow.test.fixtures.setup_fixtures import MetricFlowTestSessionState from metricflow.test.plan_utils import assert_plan_snapshot_text_equal @@ -235,7 +238,25 @@ def test_constrained_metric_not_combined( # noqa: D mf_test_session_state=mf_test_session_state, dataflow_plan_builder=dataflow_plan_builder, query_spec=MetricFlowQuerySpec( - metric_specs=(MetricSpec(element_name="booking_value"), MetricSpec(element_name="instant_booking_value")), + metric_specs=( + MetricSpec(element_name="booking_value"), + MetricSpec( + element_name="instant_booking_value", + constraint=SpecWhereClauseConstraint( + where_condition="is_instant", + linkable_names=("is_instant",), + linkable_spec_set=LinkableSpecSet( + dimension_specs=( + DimensionSpec( + element_name="is_instant", + identifier_links=(), + ), + ) + ), + execution_parameters=SqlBindParameters(), + ), + ), + ), dimension_specs=(DataSet.metric_time_dimension_spec(TimeGranularity.DAY),), ), expected_num_sources_in_unoptimized=2, diff --git a/metricflow/test/plan_conversion/test_dataflow_to_sql_plan.py b/metricflow/test/plan_conversion/test_dataflow_to_sql_plan.py index 786c9b6372..217e2351a0 100644 --- a/metricflow/test/plan_conversion/test_dataflow_to_sql_plan.py +++ b/metricflow/test/plan_conversion/test_dataflow_to_sql_plan.py @@ -1633,7 +1633,24 @@ def test_join_to_scd_dimension( """Tests conversion of a plan using a dimension with a validity window inside a measure constraint""" dataflow_plan = scd_dataflow_plan_builder.build_plan( MetricFlowQuerySpec( - metric_specs=(MetricSpec(element_name="family_bookings"),), + metric_specs=( + MetricSpec( + element_name="family_bookings", + constraint=SpecWhereClauseConstraint( + where_condition="listing__capacity > 2", + linkable_names=("listing__capacity",), + linkable_spec_set=LinkableSpecSet( + dimension_specs=( + DimensionSpec( + element_name="capacity", + identifier_links=(IdentifierReference(element_name="listing"),), + ), + ), + ), + execution_parameters=SqlBindParameters(), + ), + ), + ), time_dimension_specs=(MTD_SPEC_DAY,), ), ) diff --git a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml index 1b50350e58..bc63d897cc 100644 --- a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml +++ b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml @@ -52,13 +52,23 @@ - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml index 45b3c133bb..83fa7a6c34 100644 --- a/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml +++ b/metricflow/test/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml @@ -52,13 +52,23 @@ - - - - - - - + + + + + + + + + + + + + + + + +