From e0fcb99a07cf8dd6d268f5598760b22ceda03736 Mon Sep 17 00:00:00 2001 From: Will Deng Date: Wed, 4 Dec 2024 11:28:15 -0500 Subject: [PATCH] Custom grain was decided to only be supported in input_metric.offset_window, so removing tests that includes them otherwise --- tests/functional/metrics/fixtures.py | 58 ++++++++++++++---------- tests/functional/metrics/test_metrics.py | 21 ++++++--- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/tests/functional/metrics/fixtures.py b/tests/functional/metrics/fixtures.py index bfd75fd4a2d..693c8a3fc4d 100644 --- a/tests/functional/metrics/fixtures.py +++ b/tests/functional/metrics/fixtures.py @@ -496,6 +496,16 @@ name: sum_order_revenue denominator: name: count_orders + + - name: sum_order_revenue_plus_one_custom_offset_window + label: "Total order revenue, plus 1 with custom offset window" + description: "The total order revenue plus 1 offset by 1 martian day" + type: derived + type_params: + metrics: + - name: sum_order_revenue + offset_window: 1 martian_day + expr: "sum_order_revenue + 1" """ disabled_metric_level_schema_yml = """ @@ -800,20 +810,21 @@ type: cumulative type_params: measure: num_visits - - name: visits_martian_day - label: Visits since start of martian_day - type: cumulative - type_params: - measure: num_visits - cumulative_type_params: - grain_to_date: martian_day - - name: visits_martian_day_window - label: Visits since start of martian_day window - type: cumulative - type_params: - measure: num_visits - cumulative_type_params: - window: 1 martian_day + # TODO: Re-enable this when custom grain is supported for this type + # - name: visits_martian_day + # label: Visits since start of martian_day + # type: cumulative + # type_params: + # measure: num_visits + # cumulative_type_params: + # grain_to_date: martian_day + # - name: visits_martian_day_window + # label: Visits since start of martian_day window + # type: cumulative + # type_params: + # measure: num_visits + # cumulative_type_params: + # window: 1 martian_day """ conversion_metric_yml = """ @@ -836,15 +847,16 @@ conversion_measure: num_orders entity: purchase window: 4 day - - name: converted_orders_over_visits_with_custom_window - label: Number of orders converted from visits with custom window - type: conversion - type_params: - conversion_type_params: - base_measure: num_visits - conversion_measure: num_orders - entity: purchase - window: 4 martian_day + # TODO: Re-enable this when custom grain is supported for this type + # - name: converted_orders_over_visits_with_custom_window + # label: Number of orders converted from visits with custom window + # type: conversion + # type_params: + # conversion_type_params: + # base_measure: num_visits + # conversion_measure: num_orders + # entity: purchase + # window: 4 martian_day """ filtered_metrics_yml = """ diff --git a/tests/functional/metrics/test_metrics.py b/tests/functional/metrics/test_metrics.py index 9905cdfa385..eddf641801b 100644 --- a/tests/functional/metrics/test_metrics.py +++ b/tests/functional/metrics/test_metrics.py @@ -252,6 +252,7 @@ def models(self): "metricflow_time_spine.sql": metricflow_time_spine_sql, "semantic_models.yml": semantic_model_purchasing_yml, "derived_metric.yml": derived_metric_yml, + "time_spine.yml": time_spine_yml, } # not strictly necessary to use "real" mock data for this test @@ -277,6 +278,7 @@ def test_derived_metric( "metric.test.count_orders", "metric.test.sum_order_revenue", "metric.test.average_order_value", + "metric.test.sum_order_revenue_plus_one_custom_offset_window", ] assert metric_ids == expected_metric_ids @@ -298,12 +300,24 @@ def test_derived_metric( "metric.test.sum_order_revenue", ] + derived_metric_with_custom_offset_window = manifest.metrics[ + "metric.test.sum_order_revenue_plus_one_custom_offset_window" + ] + assert len(derived_metric_with_custom_offset_window.input_metrics) == 1 + assert derived_metric_with_custom_offset_window.input_metrics[ + 0 + ].offset_window == MetricTimeWindow(count=1, granularity="martian_day") + # actually compile results = run_dbt(["compile", "--select", "downstream_model"]) compiled_code = results[0].node.compiled_code # make sure all these metrics properties show up in compiled SQL for metric_name in manifest.metrics: + if metric_name == "metric.test.sum_order_revenue_plus_one_custom_offset_window": + # Skip this metric + continue + parsed_metric_node = manifest.metrics[metric_name] for property in [ "name", @@ -389,9 +403,6 @@ def test_conversion_metric( "metric.test.converted_orders_over_visits_with_window": MetricTimeWindow( count=4, granularity=TimeGranularity.DAY.value ), - "metric.test.converted_orders_over_visits_with_custom_window": MetricTimeWindow( - count=4, granularity="martian_day" - ), } assert set(metric_ids) == set(expected_metric_ids.keys()) assert manifest.metrics[ @@ -476,10 +487,6 @@ def test_cumulative_metric(self, project): "metric.test.cumulative_visits": CumulativeTypeParams( period_agg=PeriodAggregation.FIRST ), - "metric.test.visits_martian_day": CumulativeTypeParams(grain_to_date="martian_day"), - "metric.test.visits_martian_day_window": CumulativeTypeParams( - window=MetricTimeWindow(count=1, granularity="martian_day"), - ), } assert metric_ids == set(expected_metric_ids_to_cumulative_type_params.keys()) for (