From a3f16935006dc52a9a3b00f6449d59aca29a6e02 Mon Sep 17 00:00:00 2001 From: Will Deng Date: Wed, 9 Oct 2024 18:59:15 -0400 Subject: [PATCH] add tests --- .../simple_manifest/metrics.yaml | 15 ++++++++- .../test_time_spine_join_rendering.py | 31 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml index 6d9116f015..e52bb2c9b7 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml +++ b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml @@ -11,7 +11,10 @@ metric: description: "average booking value metric" type: simple type_params: - measure: average_booking_value + measure: + name: average_booking_value + filter: "average_booking_value > 10" + --- metric: name: "instant_bookings" @@ -629,6 +632,16 @@ metric: fill_nulls_with: 0 time_granularity: week --- +metric: + name: instant_bookings_with_measure_filter + description: simple metric joining to time spine with measure filter + type: simple + type_params: + measure: + name: bookings + join_to_timespine: true + filter: "{{ Dimension('booking__is_instant') }}" +--- metric: name: every_two_days_bookers_fill_nulls_with_0 description: cumulative metric filling 0 diff --git a/tests_metricflow/query_rendering/test_time_spine_join_rendering.py b/tests_metricflow/query_rendering/test_time_spine_join_rendering.py index 261b644677..43e0438a01 100644 --- a/tests_metricflow/query_rendering/test_time_spine_join_rendering.py +++ b/tests_metricflow/query_rendering/test_time_spine_join_rendering.py @@ -152,3 +152,34 @@ def test_join_to_time_spine_with_queried_time_constraint( dataflow_plan_builder=dataflow_plan_builder, query_spec=query_spec, ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_time_spine_with_input_measure_constraint( + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, + query_parser: MetricFlowQueryParser, +) -> None: + """Check filter hierarchy. + + Ensure that the measure filter 'booking__is_instant' doesn't get applied again post-aggregation. + """ + query_spec = query_parser.parse_and_validate_query( + metric_names=("instant_bookings_with_measure_filter",), + group_by_names=("metric_time__day", "booking__is_instant"), + where_constraints=[ + PydanticWhereFilter(where_sql_template="{{ TimeDimension('metric_time', 'day') }} > '2020-01-01'") + ], + ).query_spec + + render_and_check( + request=request, + mf_test_configuration=mf_test_configuration, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + dataflow_plan_builder=dataflow_plan_builder, + query_spec=query_spec, + )