Skip to content

Commit

Permalink
fixup! Check query tests for custom granularity
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Sep 20, 2024
1 parent 6bdc926 commit 97bf039
Showing 1 changed file with 30 additions and 37 deletions.
67 changes: 30 additions & 37 deletions tests_metricflow/integration/test_cases/itest_granularity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,10 @@ integration_test:
check_query: |
SELECT
b.martian_day AS booking__ds__martian_day
, SUM(a.bookings) AS bookings
FROM (
SELECT
DATE_TRUNC('day', ds) AS booking__ds__day
, 1 AS bookings
FROM {{ source_schema }}.fct_bookings
) a
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings a
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine b
ON a.booking__ds__day = b.ds
ON {{ render_date_trunc("a.ds", TimeGranularity.DAY) }} = b.ds
GROUP BY b.martian_day
---
integration_test:
Expand All @@ -340,17 +335,12 @@ integration_test:
check_query: |
SELECT
c.martian_day AS listing__ds__martian_day
, SUM(b.bookings) AS bookings
FROM (
SELECT
DATE_TRUNC('day', l.created_at) AS listing__ds__day
, 1 AS bookings
FROM {{ source_schema }}.fct_bookings a
LEFT OUTER JOIN {{ source_schema }}.dim_listings_latest l
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings a
LEFT OUTER JOIN {{ source_schema }}.dim_listings_latest l
ON a.listing_id = l.listing_id
) b
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine c
ON b.listing__ds__day = c.ds
ON {{ render_date_trunc("l.created_at", TimeGranularity.DAY) }} = c.ds
GROUP BY c.martian_day
---
integration_test:
Expand All @@ -369,15 +359,16 @@ integration_test:
, AVG(txn_revenue) OVER (PARTITION BY metric_time__martian_day) AS trailing_2_months_revenue
FROM (
SELECT
subq_5.martian_day AS metric_time__martian_day
ts2.martian_day AS metric_time__martian_day
, ts.ds AS metric_time__day
, SUM(r.revenue) AS txn_revenue
FROM {{ source_schema }}.mf_time_spine ts
INNER JOIN {{ source_schema }}.fct_revenue r
ON (DATE_TRUNC('day', r.created_at) <= ts.ds) AND (DATE_TRUNC('day', r.created_at) > ts.ds - INTERVAL 2 month)
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine subq_5
ON ts.ds = subq_5.ds
GROUP BY subq_5.martian_day, ts.ds
ON ({{ render_date_trunc("r.created_at", TimeGranularity.DAY) }} <= ts.ds)
AND ({{ render_date_trunc("l.created_at", TimeGranularity.DAY) }} > {{ render_date_sub("ts", "ds", 2, TimeGranularity.MONTH) }})
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine ts2
ON ts.ds = ts2.ds
GROUP BY ts2.martian_day, ts.ds
) ts
) subq_9
GROUP BY metric_time__martian_day, trailing_2_months_revenue
Expand All @@ -399,28 +390,28 @@ integration_test:
, MAX(subq_14.bookers) AS bookers
FROM (
SELECT
subq_5.martian_day AS metric_time__martian_day
ts2.martian_day AS metric_time__martian_day
, SUM(subq_4.booking_value) AS booking_value
FROM (
SELECT
ts.ds AS metric_time__day
, b.booking_value AS booking_value
FROM {{ source_schema }}.mf_time_spine ts
INNER JOIN {{ source_schema }}.fct_bookings b
ON ts.ds - INTERVAL 1 week = DATE_TRUNC('day', b.ds)
ON {{ render_date_sub("ts", "ds", 1, TimeGranularity.WEEK) }} = {{ render_date_trunc("b.ds", TimeGranularity.DAY) }}
) subq_4
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine subq_5
ON subq_4.metric_time__day = subq_5.ds
GROUP BY subq_5.martian_day
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine ts2
ON subq_4.metric_time__day = ts2.ds
GROUP BY ts2.martian_day
) subq_8
FULL OUTER JOIN (
SELECT
subq_11.martian_day AS metric_time__martian_day
ts3.martian_day AS metric_time__martian_day
, COUNT(DISTINCT b.guest_id) AS bookers
FROM {{ source_schema }}.fct_bookings b
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine subq_11
ON DATE_TRUNC('day', b.ds) = subq_11.ds
GROUP BY subq_11.martian_day
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine ts3
ON {{ render_date_trunc("b.ds", TimeGranularity.DAY) }} = ts3.ds
GROUP BY ts3.martian_day
) subq_14
ON subq_8.metric_time__martian_day = subq_14.metric_time__martian_day
GROUP BY COALESCE(subq_8.metric_time__martian_day, subq_14.metric_time__martian_day)
Expand All @@ -441,21 +432,23 @@ integration_test:
FROM (
SELECT
ts.martian_day AS metric_time__martian_day
, DATE_TRUNC('month', l.created_at) AS listing__ds__month
, {{ render_date_trunc("l.created_at", TimeGranularity.MONTH) }} AS listing__ds__month
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings b
LEFT OUTER JOIN {{ source_schema }}.dim_listings_latest l ON b.listing_id = l.listing_id
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine ts ON DATE_TRUNC('day', b.ds) = ts.ds
GROUP BY ts.martian_day, DATE_TRUNC('month', l.created_at)
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine ts
ON {{ render_date_trunc("b.ds", TimeGranularity.DAY) }} = ts.ds
GROUP BY ts.martian_day, {{ render_date_trunc("l.created_at", TimeGranularity.MONTH) }}
) subq_10
FULL OUTER JOIN (
SELECT
ts.martian_day AS metric_time__martian_day
, DATE_TRUNC('month', l.created_at) AS listing__ds__month
, {{ render_date_trunc("l.created_at", TimeGranularity.MONTH) }} AS listing__ds__month
, SUM(1) AS listings
FROM {{ source_schema }}.dim_listings_latest l
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine ts ON DATE_TRUNC('day', l.created_at) = ts.ds
GROUP BY ts.martian_day, DATE_TRUNC('month', l.created_at)
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine ts
ON {{ render_date_trunc("l.created_at", TimeGranularity.DAY) }} = ts.ds
GROUP BY ts.martian_day, {{ render_date_trunc("l.created_at", TimeGranularity.MONTH) }}
) subq_16
ON (subq_10.metric_time__martian_day = subq_16.metric_time__martian_day)
AND (subq_10.listing__ds__month = subq_16.listing__ds__month)
Expand Down

0 comments on commit 97bf039

Please sign in to comment.