Skip to content

Commit

Permalink
Add test for nested offset_to_grain
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Nov 15, 2024
1 parent 76722a0 commit 60624bc
Show file tree
Hide file tree
Showing 4 changed files with 937 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ metric:
metric:
name: "bookings_growth_since_start_of_month"
description: |
percentage growth of bookings since the start of the month,
number of bookings since the start of the month,
used to test derived metrics with an offset_to_grain.
type: derived
type_params:
Expand All @@ -506,6 +506,18 @@ metric:
offset_to_grain: month
alias: bookings_at_start_of_month
---
metric:
name: bookings_offset_to_grain_twice
description: tests a nested offset_to_grain metric
type: derived
type_params:
expr: bookings_qtd * 2
metrics:
- name: bookings_growth_since_start_of_month
offset_to_grain: quarter
alias: bookings_qtd
filter: "{{ TimeDimension('metric_time', 'month') }} >= '2020-01-01'"
---
metric:
name: "bookings_month_start_compared_to_1_month_prior"
description: |
Expand Down
29 changes: 29 additions & 0 deletions tests_metricflow/query_rendering/test_derived_metric_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,3 +858,32 @@ def test_nested_offset_metric_with_tiered_filters(
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_nested_offset_to_grain_metric_with_tiered_filters(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
query_parser: MetricFlowQueryParser,
sql_client: SqlClient,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
) -> None:
"""Tests that filters at different tiers are applied appropriately for derived metrics with offset to grain."""
# TODO: test with Trino, hard-coded filters might fail
query_spec = query_parser.parse_and_validate_query(
metric_names=("bookings_offset_to_grain_twice",),
group_by_names=("metric_time__day",),
where_constraints=[
PydanticWhereFilter(where_sql_template=("{{ Entity('listing') }} IS NOT NULL")),
],
).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,
)
Loading

0 comments on commit 60624bc

Please sign in to comment.