Skip to content

Commit

Permalink
Add test for parsing a metric with a custom grain offset_window
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamDee committed Dec 4, 2024
1 parent 250da92 commit 2d0374b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,16 @@ metric:
- name: bookings_offset_once
offset_window: 2 days
---
metric:
name: "bookings_offset_martian_day"
description: bookings metric offset by a martian day.
type: derived
type_params:
expr: 2 * bookings
metrics:
- name: bookings
offset_window: 1 martian_day
---
metric:
name: bookings_at_start_of_month
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging

from dbt_semantic_interfaces.implementations.metric import PydanticMetricTimeWindow
from dbt_semantic_interfaces.references import MetricReference
from dbt_semantic_interfaces.type_enums import TimeGranularity
from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup
Expand All @@ -21,3 +22,18 @@ def test_min_queryable_time_granularity_for_different_agg_time_grains( # noqa:
# Since `monthly_bookings_to_daily_bookings` is based on metrics with DAY and MONTH aggregation time grains,
# the minimum queryable grain should be MONTH.
assert min_queryable_grain == TimeGranularity.MONTH


def test_custom_offset_window_for_metric(
simple_semantic_manifest_lookup: SemanticManifestLookup,
) -> None:
"""Test offset window with custom grain supplied.
TODO: As of now, the functionality of an offset window with a custom grain is not supported in MF.
This test is added to show that at least the parsing is successful using a custom grain offset window.
Once support for that is added in MF + relevant tests, this test can be removed.
"""
metric = simple_semantic_manifest_lookup.metric_lookup.get_metric(MetricReference("bookings_offset_martian_day"))

assert len(metric.input_metrics) == 1
assert metric.input_metrics[0].offset_window == PydanticMetricTimeWindow(count=1, granularity="martian_day")

0 comments on commit 2d0374b

Please sign in to comment.