-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for cumulative metric with non-day granularity (#992)
- Loading branch information
1 parent
f7b3c74
commit 2486b4b
Showing
17 changed files
with
1,279 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...s/semantic_manifest_yamls/extended_date_manifest/metrics/bookings_monthly_cumulative.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
metric: | ||
name: trailing_3_months_bookings | ||
description: Prior 3 months' bookings. Tests a cumulative metric with non-day granularity. | ||
type: cumulative | ||
type_params: | ||
measure: bookings_monthly | ||
window: 3 month |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
...ulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_month__plan0.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_8.metric_time__month | ||
, subq_8.bookings_monthly AS trailing_3_months_bookings | ||
FROM ( | ||
-- Aggregate Measures | ||
SELECT | ||
subq_7.metric_time__month | ||
, SUM(subq_7.bookings_monthly) AS bookings_monthly | ||
FROM ( | ||
-- Constrain Time Range to [2020-03-05T00:00:00, 2021-01-04T00:00:00] | ||
SELECT | ||
subq_6.metric_time__month | ||
, subq_6.bookings_monthly | ||
FROM ( | ||
-- Pass Only Elements: ['bookings_monthly', 'metric_time__month'] | ||
SELECT | ||
subq_5.metric_time__month | ||
, subq_5.bookings_monthly | ||
FROM ( | ||
-- Join Self Over Time Range | ||
SELECT | ||
subq_3.metric_time__month AS metric_time__month | ||
, subq_2.monthly_ds__month AS monthly_ds__month | ||
, subq_2.monthly_ds__quarter AS monthly_ds__quarter | ||
, subq_2.monthly_ds__year AS monthly_ds__year | ||
, subq_2.monthly_ds__extract_year AS monthly_ds__extract_year | ||
, subq_2.monthly_ds__extract_quarter AS monthly_ds__extract_quarter | ||
, subq_2.monthly_ds__extract_month AS monthly_ds__extract_month | ||
, subq_2.booking__monthly_ds__month AS booking__monthly_ds__month | ||
, subq_2.booking__monthly_ds__quarter AS booking__monthly_ds__quarter | ||
, subq_2.booking__monthly_ds__year AS booking__monthly_ds__year | ||
, subq_2.booking__monthly_ds__extract_year AS booking__monthly_ds__extract_year | ||
, subq_2.booking__monthly_ds__extract_quarter AS booking__monthly_ds__extract_quarter | ||
, subq_2.booking__monthly_ds__extract_month AS booking__monthly_ds__extract_month | ||
, subq_2.metric_time__quarter AS metric_time__quarter | ||
, subq_2.metric_time__year AS metric_time__year | ||
, subq_2.metric_time__extract_year AS metric_time__extract_year | ||
, subq_2.metric_time__extract_quarter AS metric_time__extract_quarter | ||
, subq_2.metric_time__extract_month AS metric_time__extract_month | ||
, subq_2.listing AS listing | ||
, subq_2.booking__listing AS booking__listing | ||
, subq_2.bookings_monthly AS bookings_monthly | ||
FROM ( | ||
-- Time Spine | ||
SELECT | ||
DATE_TRUNC(subq_4.ds, month) AS metric_time__month | ||
FROM ***************************.mf_time_spine subq_4 | ||
WHERE subq_4.ds BETWEEN '2020-03-05' AND '2021-01-04' | ||
GROUP BY | ||
metric_time__month | ||
) subq_3 | ||
INNER JOIN ( | ||
-- Constrain Time Range to [2019-12-05T00:00:00, 2021-01-04T00:00:00] | ||
SELECT | ||
subq_1.monthly_ds__month | ||
, subq_1.monthly_ds__quarter | ||
, subq_1.monthly_ds__year | ||
, subq_1.monthly_ds__extract_year | ||
, subq_1.monthly_ds__extract_quarter | ||
, subq_1.monthly_ds__extract_month | ||
, subq_1.booking__monthly_ds__month | ||
, subq_1.booking__monthly_ds__quarter | ||
, subq_1.booking__monthly_ds__year | ||
, subq_1.booking__monthly_ds__extract_year | ||
, subq_1.booking__monthly_ds__extract_quarter | ||
, subq_1.booking__monthly_ds__extract_month | ||
, subq_1.metric_time__month | ||
, subq_1.metric_time__quarter | ||
, subq_1.metric_time__year | ||
, subq_1.metric_time__extract_year | ||
, subq_1.metric_time__extract_quarter | ||
, subq_1.metric_time__extract_month | ||
, subq_1.listing | ||
, subq_1.booking__listing | ||
, subq_1.bookings_monthly | ||
FROM ( | ||
-- Metric Time Dimension 'monthly_ds' | ||
SELECT | ||
subq_0.monthly_ds__month | ||
, subq_0.monthly_ds__quarter | ||
, subq_0.monthly_ds__year | ||
, subq_0.monthly_ds__extract_year | ||
, subq_0.monthly_ds__extract_quarter | ||
, subq_0.monthly_ds__extract_month | ||
, subq_0.booking__monthly_ds__month | ||
, subq_0.booking__monthly_ds__quarter | ||
, subq_0.booking__monthly_ds__year | ||
, subq_0.booking__monthly_ds__extract_year | ||
, subq_0.booking__monthly_ds__extract_quarter | ||
, subq_0.booking__monthly_ds__extract_month | ||
, subq_0.monthly_ds__month AS metric_time__month | ||
, subq_0.monthly_ds__quarter AS metric_time__quarter | ||
, subq_0.monthly_ds__year AS metric_time__year | ||
, subq_0.monthly_ds__extract_year AS metric_time__extract_year | ||
, subq_0.monthly_ds__extract_quarter AS metric_time__extract_quarter | ||
, subq_0.monthly_ds__extract_month AS metric_time__extract_month | ||
, subq_0.listing | ||
, subq_0.booking__listing | ||
, subq_0.bookings_monthly | ||
FROM ( | ||
-- Read Elements From Semantic Model 'bookings_monthly_source' | ||
SELECT | ||
bookings_monthly_source_src_10026.bookings_monthly | ||
, DATE_TRUNC(bookings_monthly_source_src_10026.ds, month) AS monthly_ds__month | ||
, DATE_TRUNC(bookings_monthly_source_src_10026.ds, quarter) AS monthly_ds__quarter | ||
, DATE_TRUNC(bookings_monthly_source_src_10026.ds, year) AS monthly_ds__year | ||
, EXTRACT(year FROM bookings_monthly_source_src_10026.ds) AS monthly_ds__extract_year | ||
, EXTRACT(quarter FROM bookings_monthly_source_src_10026.ds) AS monthly_ds__extract_quarter | ||
, EXTRACT(month FROM bookings_monthly_source_src_10026.ds) AS monthly_ds__extract_month | ||
, DATE_TRUNC(bookings_monthly_source_src_10026.ds, month) AS booking__monthly_ds__month | ||
, DATE_TRUNC(bookings_monthly_source_src_10026.ds, quarter) AS booking__monthly_ds__quarter | ||
, DATE_TRUNC(bookings_monthly_source_src_10026.ds, year) AS booking__monthly_ds__year | ||
, EXTRACT(year FROM bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__extract_year | ||
, EXTRACT(quarter FROM bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__extract_quarter | ||
, EXTRACT(month FROM bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__extract_month | ||
, bookings_monthly_source_src_10026.listing_id AS listing | ||
, bookings_monthly_source_src_10026.listing_id AS booking__listing | ||
FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10026 | ||
) subq_0 | ||
) subq_1 | ||
WHERE subq_1.metric_time__month BETWEEN '2019-12-05' AND '2021-01-04' | ||
) subq_2 | ||
ON | ||
( | ||
subq_2.metric_time__month <= subq_3.metric_time__month | ||
) AND ( | ||
subq_2.metric_time__month > DATE_SUB(CAST(subq_3.metric_time__month AS DATETIME), INTERVAL 3 month) | ||
) | ||
) subq_5 | ||
) subq_6 | ||
WHERE subq_6.metric_time__month BETWEEN '2020-03-05' AND '2021-01-04' | ||
) subq_7 | ||
GROUP BY | ||
metric_time__month | ||
) subq_8 |
36 changes: 36 additions & 0 deletions
36
...tric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_month__plan0_optimized.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-- Join Self Over Time Range | ||
-- Pass Only Elements: ['bookings_monthly', 'metric_time__month'] | ||
-- Constrain Time Range to [2020-03-05T00:00:00, 2021-01-04T00:00:00] | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_12.metric_time__month AS metric_time__month | ||
, SUM(subq_11.bookings_monthly) AS trailing_3_months_bookings | ||
FROM ( | ||
-- Time Spine | ||
SELECT | ||
DATE_TRUNC(ds, month) AS metric_time__month | ||
FROM ***************************.mf_time_spine subq_13 | ||
WHERE ds BETWEEN '2020-03-05' AND '2021-01-04' | ||
GROUP BY | ||
metric_time__month | ||
) subq_12 | ||
INNER JOIN ( | ||
-- Read Elements From Semantic Model 'bookings_monthly_source' | ||
-- Metric Time Dimension 'monthly_ds' | ||
-- Constrain Time Range to [2019-12-05T00:00:00, 2021-01-04T00:00:00] | ||
SELECT | ||
DATE_TRUNC(ds, month) AS metric_time__month | ||
, bookings_monthly | ||
FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10026 | ||
WHERE DATE_TRUNC(ds, month) BETWEEN '2019-12-05' AND '2021-01-04' | ||
) subq_11 | ||
ON | ||
( | ||
subq_11.metric_time__month <= subq_12.metric_time__month | ||
) AND ( | ||
subq_11.metric_time__month > DATE_SUB(CAST(subq_12.metric_time__month AS DATETIME), INTERVAL 3 month) | ||
) | ||
WHERE subq_12.metric_time__month BETWEEN '2020-03-05' AND '2021-01-04' | ||
GROUP BY | ||
metric_time__month |
Oops, something went wrong.