diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/ambiguous_resolution_manifest/metrics.yaml b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/ambiguous_resolution_manifest/metrics.yaml index 01fa224f3b..a859e04f41 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/ambiguous_resolution_manifest/metrics.yaml +++ b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/ambiguous_resolution_manifest/metrics.yaml @@ -149,8 +149,8 @@ metric: type: derived time_granularity: year type_params: - expr: simple_metric_with_time_granularity_and_metric_time_filter * 2 + expr: simple_metric_with_time_granularity * 2 metrics: - - name: simple_metric_with_time_granularity_and_metric_time_filter + - name: simple_metric_with_time_granularity filter: | {{ TimeDimension('metric_time') }} = '2020-01-01' 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..2e29e96670 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 @@ -783,3 +783,14 @@ metric: name: listings filter: "{{ Metric('views', ['listing']) }} > 10" time_granularity: week +--- +metric: + name: bookings_starting_2020 + description: Bookings starting in 2020. Used to test a metric with an ambiguous filter in on its input metric. + type: derived + type_params: + expr: bookings + metrics: + - name: bookings + filter: "{{ TimeDimension('metric_time') }} >= '2020-01-01'" + time_granularity: week diff --git a/metricflow-semantics/tests_metricflow_semantics/query/test_metric_time_granularity.py b/metricflow-semantics/tests_metricflow_semantics/query/test_metric_time_granularity.py index e1ab2577e3..9335c39f20 100644 --- a/metricflow-semantics/tests_metricflow_semantics/query/test_metric_time_granularity.py +++ b/metricflow-semantics/tests_metricflow_semantics/query/test_metric_time_granularity.py @@ -165,7 +165,7 @@ def test_derived_metric_with_defined_metric_time_filter_on_input_metric( query_spec = ambiguous_resolution_query_parser.parse_and_validate_query( metric_names=["derived_metric_with_time_granularity_and_inner_metric_time_filter"] ).query_spec - assert 0, "this don't werk" + assert_object_snapshot_equal( request=request, mf_test_configuration=mf_test_configuration, diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_with_defined_metric_time_filter_on_input_metric__result_0.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_with_defined_metric_time_filter_on_input_metric__result_0.txt index ef462b6c37..a4f878ace8 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_with_defined_metric_time_filter_on_input_metric__result_0.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_metric_time_granularity.py/MetricFlowQuerySpec/test_derived_metric_with_defined_metric_time_filter_on_input_metric__result_0.txt @@ -8,7 +8,7 @@ MetricFlowQuerySpec( filter_location=WhereFilterLocation( metric_references=( MetricReference( - element_name='simple_metric_with_time_granularity_and_metric_time_filter', + element_name='simple_metric_with_time_granularity', ), ), ), @@ -21,10 +21,7 @@ MetricFlowQuerySpec( where_filter_intersection=PydanticWhereFilterIntersection( where_filters=[ PydanticWhereFilter( - where_sql_template="{{ TimeDimension('metric_time') }} > '2020-01-01'\n", - ), - PydanticWhereFilter( - where_sql_template="{{ TimeDimension('metric_time') }} = '2020-01-01'", + where_sql_template="{{ TimeDimension('metric_time') }} = '2020-01-01'\n", ), ], ), @@ -33,7 +30,7 @@ MetricFlowQuerySpec( ElementPathKey( element_name='metric_time', element_type=TIME_DIMENSION, - time_granularity=QUARTER, + time_granularity=YEAR, ): ( LinkableDimension( defined_in_semantic_model=SemanticModelReference( @@ -50,7 +47,7 @@ MetricFlowQuerySpec( 'DERIVED_TIME_GRANULARITY', 'METRIC_TIME', ), - time_granularity=QUARTER, + time_granularity=YEAR, ), ), }, diff --git a/tests_metricflow/integration/test_cases/itest_metrics.yaml b/tests_metricflow/integration/test_cases/itest_metrics.yaml index 52b805f9ea..fa27b5c72a 100644 --- a/tests_metricflow/integration/test_cases/itest_metrics.yaml +++ b/tests_metricflow/integration/test_cases/itest_metrics.yaml @@ -2215,3 +2215,14 @@ integration_test: GROUP BY {{ render_date_trunc("ds", TimeGranularity.DAY) }} ) a ON b.ds = a.ds WHERE {{ render_between_time_constraint("b.ds", "2020-01-03", "2020-01-03") }} +--- +integration_test: + name: metric_time_filter_on_input_metric + description: Test a metric with a filter defined on its input metric. + model: SIMPLE_MODEL + metrics: ["bookings_starting_2020"] + check_query: | + SELECT + SUM(1) AS bookings_starting_2020 + FROM {{ source_schema }}.fct_bookings + WHERE {{ render_date_trunc("ds", TimeGranularity.WEEK) }} >= '2020-01-01'