Skip to content

Commit

Permalink
Add test case for metric filter defined on ratio metric
Browse files Browse the repository at this point in the history
This test case demonstrates the bug, as you can see in CI failures for this commit. This error is only triggered in e2e tests where we ensure the ComputeMetricsBranchCombiner is used.
  • Loading branch information
courtneyholcomb committed May 15, 2024
1 parent a446ffa commit 5357c8e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,14 @@ metric:
type_params:
measure: listings
filter: "{{ Metric('bookings', ['listing']) }} > 2"
---
metric:
name: popular_listing_bookings_per_booker
description: bookings per booker for listings with at least 10 views
type: ratio
type_params:
numerator:
name: listings
denominator:
name: listings
filter: "{{ Metric('views', ['listing']) }} > 10"
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
'listing__min_booking_value',
'listing__nested_fill_nulls_without_time_spine',
'listing__non_referred_bookings_pct',
'listing__popular_listing_bookings_per_booker',
'listing__referred_bookings',
'listing__smallest_listing',
'listing__twice_bookings_fill_nulls_with_0_without_time_spine',
Expand Down Expand Up @@ -289,13 +290,15 @@
'user__listing__user__min_booking_value',
'user__listing__user__nested_fill_nulls_without_time_spine',
'user__listing__user__non_referred_bookings_pct',
'user__listing__user__popular_listing_bookings_per_booker',
'user__listing__user__referred_bookings',
'user__listing__user__smallest_listing',
'user__listing__user__twice_bookings_fill_nulls_with_0_without_time_spine',
'user__listing__user__views',
'user__listing__user__views_times_booking_value',
'user__listings',
'user__lux_listings',
'user__popular_listing_bookings_per_booker',
'user__regional_starting_balance_ratios',
'user__revenue',
'user__revenue_all_time',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Semantic Model Entity Links Name
("('listing',)", "('listing',)") min_booking_value ['JOINED', 'METRIC']
("('listing',)", "('listing',)") nested_fill_nulls_without_time_spine ['JOINED', 'METRIC']
("('listing',)", "('listing',)") non_referred_bookings_pct ['JOINED', 'METRIC']
("('listing',)", "('listing',)") popular_listing_bookings_per_booker ['JOINED', 'METRIC']
("('listing',)", "('listing',)") referred_bookings ['JOINED', 'METRIC']
("('listing',)", "('listing',)") smallest_listing ['JOINED', 'METRIC']
("('listing',)", "('listing',)") twice_bookings_fill_nulls_with_0_without_time_spine ['JOINED', 'METRIC']
Expand Down Expand Up @@ -137,6 +138,7 @@ Semantic Model Entity Links Name
("('user',)", "('listing', 'user')") min_booking_value ['JOINED', 'METRIC']
("('user',)", "('listing', 'user')") nested_fill_nulls_without_time_spine ['JOINED', 'METRIC']
("('user',)", "('listing', 'user')") non_referred_bookings_pct ['JOINED', 'METRIC']
("('user',)", "('listing', 'user')") popular_listing_bookings_per_booker ['JOINED', 'METRIC']
("('user',)", "('listing', 'user')") referred_bookings ['JOINED', 'METRIC']
("('user',)", "('listing', 'user')") smallest_listing ['JOINED', 'METRIC']
("('user',)", "('listing', 'user')") twice_bookings_fill_nulls_with_0_without_time_spine ['JOINED', 'METRIC']
Expand All @@ -150,6 +152,7 @@ Semantic Model Entity Links Name
("('user',)", "('user',)") largest_listing ['JOINED', 'METRIC']
("('user',)", "('user',)") listings ['JOINED', 'METRIC']
("('user',)", "('user',)") lux_listings ['JOINED', 'METRIC']
("('user',)", "('user',)") popular_listing_bookings_per_booker ['JOINED', 'METRIC']
("('user',)", "('user',)") regional_starting_balance_ratios ['JOINED', 'METRIC']
("('user',)", "('user',)") revenue ['JOINED', 'METRIC']
("('user',)", "('user',)") revenue_all_time ['JOINED', 'METRIC']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
'company__user__company__largest_listing',
'company__user__company__listings',
'company__user__company__lux_listings',
'company__user__company__popular_listing_bookings_per_booker',
'company__user__company__regional_starting_balance_ratios',
'company__user__company__revenue',
'company__user__company__revenue_all_time',
Expand Down Expand Up @@ -359,6 +360,7 @@
'listing__min_booking_value',
'listing__nested_fill_nulls_without_time_spine',
'listing__non_referred_bookings_pct',
'listing__popular_listing_bookings_per_booker',
'listing__referred_bookings',
'listing__smallest_listing',
'listing__twice_bookings_fill_nulls_with_0_without_time_spine',
Expand Down Expand Up @@ -411,6 +413,7 @@
'lux_listing__listing__lux_listing__min_booking_value',
'lux_listing__listing__lux_listing__nested_fill_nulls_without_time_spine',
'lux_listing__listing__lux_listing__non_referred_bookings_pct',
'lux_listing__listing__lux_listing__popular_listing_bookings_per_booker',
'lux_listing__listing__lux_listing__referred_bookings',
'lux_listing__listing__lux_listing__smallest_listing',
'lux_listing__listing__lux_listing__twice_bookings_fill_nulls_with_0_without_time_spine',
Expand Down Expand Up @@ -521,13 +524,15 @@
'user__listing__user__min_booking_value',
'user__listing__user__nested_fill_nulls_without_time_spine',
'user__listing__user__non_referred_bookings_pct',
'user__listing__user__popular_listing_bookings_per_booker',
'user__listing__user__referred_bookings',
'user__listing__user__smallest_listing',
'user__listing__user__twice_bookings_fill_nulls_with_0_without_time_spine',
'user__listing__user__views',
'user__listing__user__views_times_booking_value',
'user__listings',
'user__lux_listings',
'user__popular_listing_bookings_per_booker',
'user__regional_starting_balance_ratios',
'user__revenue',
'user__revenue_all_time',
Expand Down
19 changes: 19 additions & 0 deletions tests_metricflow/integration/test_cases/itest_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2067,3 +2067,22 @@ integration_test:
) subq
ON l.listing_id = subq.listing_id
WHERE view__listing__views > 2
---
integration_test:
name: test_filter_defined_on_ratio_metric
description: Query a ratio metric with a metric-level filter
model: SIMPLE_MODEL
metrics: ["popular_listing_bookings_per_booker"]
check_query: |
SELECT
CAST(SUM(1) AS DOUBLE) / CAST(NULLIF(SUM(1), 0) AS DOUBLE) AS popular_listing_bookings_per_booker
FROM {{ source_schema }}.dim_listings_latest l
LEFT OUTER JOIN (
SELECT
listing_id
, SUM(1) AS views
FROM {{ source_schema }}.fct_views v
GROUP BY listing_id
) metric_subquery
ON l.listing_id = metric_subquery.listing_id
WHERE views > 10

0 comments on commit 5357c8e

Please sign in to comment.