Skip to content

Commit

Permalink
Custom grain was decided to only be supported in input_metric.offset_…
Browse files Browse the repository at this point in the history
…window, so removing tests that includes them otherwise
  • Loading branch information
WilliamDee committed Dec 4, 2024
1 parent f73f29d commit e0fcb99
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
58 changes: 35 additions & 23 deletions tests/functional/metrics/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -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 = """
Expand All @@ -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 = """
Expand Down
21 changes: 14 additions & 7 deletions tests/functional/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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",
Expand Down Expand Up @@ -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[
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit e0fcb99

Please sign in to comment.