Skip to content

Commit

Permalink
Add test to demonstrate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Nov 14, 2024
1 parent df48dd8 commit b990eeb
Show file tree
Hide file tree
Showing 4 changed files with 827 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ metric:
alias: bookings_2_weeks_ago
---
metric:
name: "bookings_offset_once"
name: bookings_offset_once
description: bookings metric offset once.
type: derived
type_params:
Expand All @@ -710,7 +710,7 @@ metric:
offset_window: 5 days
---
metric:
name: "bookings_offset_twice"
name: bookings_offset_twice
description: bookings metric offset twice.
type: derived
type_params:
Expand All @@ -719,6 +719,22 @@ metric:
- name: bookings_offset_once
offset_window: 2 days
---
metric:
name: bookings_offset_twice_with_tiered_filters
description: bookings metric offset twice with tiered filters
type: derived
type_params:
expr: bookings
metrics:
- name: bookings_offset_once
offset_window: 1 month
filter:
- "{{ TimeDimension('metric_time', 'month') }} >= '2019-01-01'"
- "{{ Dimension('booking__is_instant') }}"
filter:
- "{{ TimeDimension('metric_time', 'year') }} >= '2020-01-01'"
- "{{ Entity('listing') }} IS NOT NULL"
---
metric:
name: bookings_at_start_of_month
description: |
Expand Down
37 changes: 37 additions & 0 deletions tests_metricflow/query_rendering/test_derived_metric_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,3 +821,40 @@ def test_derived_metric_that_defines_the_same_alias_in_different_components(
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_nested_offset_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.
This includes filters at the input metric, metric, and query level. At each tier there are filters on both
metric_time / agg time and another dimension, which might have different behaviors.
"""
# TODO: test with Trino, hard-coded filters might fail
query_spec = query_parser.parse_and_validate_query(
metric_names=("bookings_offset_twice_with_tiered_filters",),
group_by_names=("metric_time__day",),
where_constraints=[
# `booking_ds` is the agg_time_dimension
PydanticWhereFilter(where_sql_template=("{{ TimeDimension('booking__ds', 'quarter') }} = '2021-01-01'")),
PydanticWhereFilter(
where_sql_template=("{{ TimeDimension('listing__created_at', 'day') }} = '2021-01-01'")
),
],
).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 b990eeb

Please sign in to comment.