-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for time offset metric based on non-default granularity (#859)
- Loading branch information
1 parent
87b5b63
commit 45a970d
Showing
17 changed files
with
833 additions
and
3 deletions.
There are no files selected for viewing
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
10 changes: 10 additions & 0 deletions
10
.../fixtures/semantic_manifest_yamls/extended_date_manifest/metrics/bookings_last_month.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,10 @@ | ||
metric: | ||
name: bookings_last_month | ||
description: bookings the prior month, based on dimension with month granularity | ||
type: derived | ||
type_params: | ||
expr: bookings_last_month | ||
metrics: | ||
- name: bookings_monthly | ||
offset_window: 1 month | ||
alias: bookings_last_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
100 changes: 100 additions & 0 deletions
100
...lQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__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,100 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_7.metric_time__month | ||
, bookings_last_month AS bookings_last_month | ||
FROM ( | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_6.metric_time__month | ||
, subq_6.bookings_monthly AS bookings_last_month | ||
FROM ( | ||
-- Aggregate Measures | ||
SELECT | ||
subq_5.metric_time__month | ||
, SUM(subq_5.bookings_monthly) AS bookings_monthly | ||
FROM ( | ||
-- Pass Only Elements: | ||
-- ['bookings_monthly', 'metric_time__month'] | ||
SELECT | ||
subq_4.metric_time__month | ||
, subq_4.bookings_monthly | ||
FROM ( | ||
-- Join to Time Spine Dataset | ||
SELECT | ||
subq_2.metric_time__month AS metric_time__month | ||
, subq_1.monthly_ds__month AS monthly_ds__month | ||
, subq_1.monthly_ds__quarter AS monthly_ds__quarter | ||
, subq_1.monthly_ds__year AS monthly_ds__year | ||
, subq_1.monthly_ds__extract_year AS monthly_ds__extract_year | ||
, subq_1.monthly_ds__extract_quarter AS monthly_ds__extract_quarter | ||
, subq_1.monthly_ds__extract_month AS monthly_ds__extract_month | ||
, subq_1.booking__monthly_ds__month AS booking__monthly_ds__month | ||
, subq_1.booking__monthly_ds__quarter AS booking__monthly_ds__quarter | ||
, subq_1.booking__monthly_ds__year AS booking__monthly_ds__year | ||
, subq_1.booking__monthly_ds__extract_year AS booking__monthly_ds__extract_year | ||
, subq_1.booking__monthly_ds__extract_quarter AS booking__monthly_ds__extract_quarter | ||
, subq_1.booking__monthly_ds__extract_month AS booking__monthly_ds__extract_month | ||
, subq_1.listing AS listing | ||
, subq_1.booking__listing AS booking__listing | ||
, subq_1.bookings_monthly AS bookings_monthly | ||
FROM ( | ||
-- Date Spine | ||
SELECT | ||
DATE_TRUNC(subq_3.ds, month) AS metric_time__month | ||
FROM ***************************.mf_time_spine subq_3 | ||
GROUP BY | ||
metric_time__month | ||
) subq_2 | ||
INNER JOIN ( | ||
-- 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_10024.bookings_monthly | ||
, DATE_TRUNC(bookings_monthly_source_src_10024.ds, month) AS monthly_ds__month | ||
, DATE_TRUNC(bookings_monthly_source_src_10024.ds, quarter) AS monthly_ds__quarter | ||
, DATE_TRUNC(bookings_monthly_source_src_10024.ds, year) AS monthly_ds__year | ||
, EXTRACT(year FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_year | ||
, EXTRACT(quarter FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_quarter | ||
, EXTRACT(month FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_month | ||
, DATE_TRUNC(bookings_monthly_source_src_10024.ds, month) AS booking__monthly_ds__month | ||
, DATE_TRUNC(bookings_monthly_source_src_10024.ds, quarter) AS booking__monthly_ds__quarter | ||
, DATE_TRUNC(bookings_monthly_source_src_10024.ds, year) AS booking__monthly_ds__year | ||
, EXTRACT(year FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_year | ||
, EXTRACT(quarter FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_quarter | ||
, EXTRACT(month FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_month | ||
, bookings_monthly_source_src_10024.listing_id AS listing | ||
, bookings_monthly_source_src_10024.listing_id AS booking__listing | ||
FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10024 | ||
) subq_0 | ||
) subq_1 | ||
ON | ||
DATE_SUB(CAST(subq_2.metric_time__month AS DATETIME), INTERVAL 1 month) = subq_1.metric_time__month | ||
) subq_4 | ||
) subq_5 | ||
GROUP BY | ||
metric_time__month | ||
) subq_6 | ||
) subq_7 |
28 changes: 28 additions & 0 deletions
28
.../BigQuery/test_derived_metric_with_month_dimension_and_offset_window__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,28 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__month | ||
, bookings_last_month AS bookings_last_month | ||
FROM ( | ||
-- Join to Time Spine Dataset | ||
-- Pass Only Elements: | ||
-- ['bookings_monthly', 'metric_time__month'] | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_10.metric_time__month AS metric_time__month | ||
, SUM(bookings_monthly_source_src_10024.bookings_monthly) AS bookings_last_month | ||
FROM ( | ||
-- Date Spine | ||
SELECT | ||
DATE_TRUNC(ds, month) AS metric_time__month | ||
FROM ***************************.mf_time_spine subq_11 | ||
GROUP BY | ||
metric_time__month | ||
) subq_10 | ||
INNER JOIN | ||
***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10024 | ||
ON | ||
DATE_SUB(CAST(subq_10.metric_time__month AS DATETIME), INTERVAL 1 month) = DATE_TRUNC(bookings_monthly_source_src_10024.ds, month) | ||
GROUP BY | ||
metric_time__month | ||
) subq_15 |
100 changes: 100 additions & 0 deletions
100
...ueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__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,100 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_7.metric_time__month | ||
, bookings_last_month AS bookings_last_month | ||
FROM ( | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_6.metric_time__month | ||
, subq_6.bookings_monthly AS bookings_last_month | ||
FROM ( | ||
-- Aggregate Measures | ||
SELECT | ||
subq_5.metric_time__month | ||
, SUM(subq_5.bookings_monthly) AS bookings_monthly | ||
FROM ( | ||
-- Pass Only Elements: | ||
-- ['bookings_monthly', 'metric_time__month'] | ||
SELECT | ||
subq_4.metric_time__month | ||
, subq_4.bookings_monthly | ||
FROM ( | ||
-- Join to Time Spine Dataset | ||
SELECT | ||
subq_2.metric_time__month AS metric_time__month | ||
, subq_1.monthly_ds__month AS monthly_ds__month | ||
, subq_1.monthly_ds__quarter AS monthly_ds__quarter | ||
, subq_1.monthly_ds__year AS monthly_ds__year | ||
, subq_1.monthly_ds__extract_year AS monthly_ds__extract_year | ||
, subq_1.monthly_ds__extract_quarter AS monthly_ds__extract_quarter | ||
, subq_1.monthly_ds__extract_month AS monthly_ds__extract_month | ||
, subq_1.booking__monthly_ds__month AS booking__monthly_ds__month | ||
, subq_1.booking__monthly_ds__quarter AS booking__monthly_ds__quarter | ||
, subq_1.booking__monthly_ds__year AS booking__monthly_ds__year | ||
, subq_1.booking__monthly_ds__extract_year AS booking__monthly_ds__extract_year | ||
, subq_1.booking__monthly_ds__extract_quarter AS booking__monthly_ds__extract_quarter | ||
, subq_1.booking__monthly_ds__extract_month AS booking__monthly_ds__extract_month | ||
, subq_1.listing AS listing | ||
, subq_1.booking__listing AS booking__listing | ||
, subq_1.bookings_monthly AS bookings_monthly | ||
FROM ( | ||
-- Date Spine | ||
SELECT | ||
DATE_TRUNC('month', subq_3.ds) AS metric_time__month | ||
FROM ***************************.mf_time_spine subq_3 | ||
GROUP BY | ||
DATE_TRUNC('month', subq_3.ds) | ||
) subq_2 | ||
INNER JOIN ( | ||
-- 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_10024.bookings_monthly | ||
, DATE_TRUNC('month', bookings_monthly_source_src_10024.ds) AS monthly_ds__month | ||
, DATE_TRUNC('quarter', bookings_monthly_source_src_10024.ds) AS monthly_ds__quarter | ||
, DATE_TRUNC('year', bookings_monthly_source_src_10024.ds) AS monthly_ds__year | ||
, EXTRACT(year FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_year | ||
, EXTRACT(quarter FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_quarter | ||
, EXTRACT(month FROM bookings_monthly_source_src_10024.ds) AS monthly_ds__extract_month | ||
, DATE_TRUNC('month', bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__month | ||
, DATE_TRUNC('quarter', bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__quarter | ||
, DATE_TRUNC('year', bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__year | ||
, EXTRACT(year FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_year | ||
, EXTRACT(quarter FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_quarter | ||
, EXTRACT(month FROM bookings_monthly_source_src_10024.ds) AS booking__monthly_ds__extract_month | ||
, bookings_monthly_source_src_10024.listing_id AS listing | ||
, bookings_monthly_source_src_10024.listing_id AS booking__listing | ||
FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10024 | ||
) subq_0 | ||
) subq_1 | ||
ON | ||
DATEADD(month, -1, subq_2.metric_time__month) = subq_1.metric_time__month | ||
) subq_4 | ||
) subq_5 | ||
GROUP BY | ||
subq_5.metric_time__month | ||
) subq_6 | ||
) subq_7 |
28 changes: 28 additions & 0 deletions
28
...atabricks/test_derived_metric_with_month_dimension_and_offset_window__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,28 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__month | ||
, bookings_last_month AS bookings_last_month | ||
FROM ( | ||
-- Join to Time Spine Dataset | ||
-- Pass Only Elements: | ||
-- ['bookings_monthly', 'metric_time__month'] | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_10.metric_time__month AS metric_time__month | ||
, SUM(bookings_monthly_source_src_10024.bookings_monthly) AS bookings_last_month | ||
FROM ( | ||
-- Date Spine | ||
SELECT | ||
DATE_TRUNC('month', ds) AS metric_time__month | ||
FROM ***************************.mf_time_spine subq_11 | ||
GROUP BY | ||
DATE_TRUNC('month', ds) | ||
) subq_10 | ||
INNER JOIN | ||
***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10024 | ||
ON | ||
DATEADD(month, -1, subq_10.metric_time__month) = DATE_TRUNC('month', bookings_monthly_source_src_10024.ds) | ||
GROUP BY | ||
subq_10.metric_time__month | ||
) subq_15 |
Oops, something went wrong.