-
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 for derived metric offsets with time filters
Derived metric offsets handle time filters correctly provided the query depends on the `metric_time` dimension. Since the DataflowPlanBuilder has an invariant in its runtime to ensure that metric_time is included in the requested query specs, this is always true in practice. Additional tests for different query patterns may be warranted when we expand support. For the time being, we simply add an illustrative query rendering test for the behavior when filter spans are at odds with the offset window selection.
- Loading branch information
Showing
13 changed files
with
3,800 additions
and
0 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
561 changes: 561 additions & 0 deletions
561
...y/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
...Plan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__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,66 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__day | ||
, bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks | ||
FROM ( | ||
-- Combine Metrics | ||
SELECT | ||
COALESCE(subq_21.metric_time__day, subq_30.metric_time__day) AS metric_time__day | ||
, MAX(subq_21.bookings) AS bookings | ||
, MAX(subq_30.bookings_2_weeks_ago) AS bookings_2_weeks_ago | ||
FROM ( | ||
-- Constrain Output with WHERE | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__day | ||
, SUM(bookings) AS bookings | ||
FROM ( | ||
-- Read Elements From Semantic Model 'bookings_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Pass Only Elements: | ||
-- ['bookings', 'metric_time__day'] | ||
SELECT | ||
DATE_TRUNC(ds, day) AS metric_time__day | ||
, 1 AS bookings | ||
FROM ***************************.fct_bookings bookings_source_src_10001 | ||
) subq_18 | ||
WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' | ||
GROUP BY | ||
metric_time__day | ||
) subq_21 | ||
FULL OUTER JOIN ( | ||
-- Constrain Output with WHERE | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__day | ||
, SUM(bookings) AS bookings_2_weeks_ago | ||
FROM ( | ||
-- Join to Time Spine Dataset | ||
-- Pass Only Elements: | ||
-- ['bookings', 'metric_time__day'] | ||
SELECT | ||
subq_25.ds AS metric_time__day | ||
, subq_23.bookings AS bookings | ||
FROM ***************************.mf_time_spine subq_25 | ||
INNER JOIN ( | ||
-- Read Elements From Semantic Model 'bookings_source' | ||
-- Metric Time Dimension 'ds' | ||
SELECT | ||
DATE_TRUNC(ds, day) AS metric_time__day | ||
, 1 AS bookings | ||
FROM ***************************.fct_bookings bookings_source_src_10001 | ||
) subq_23 | ||
ON | ||
DATE_SUB(CAST(subq_25.ds AS DATETIME), INTERVAL 14 day) = subq_23.metric_time__day | ||
) subq_27 | ||
WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' | ||
GROUP BY | ||
metric_time__day | ||
) subq_30 | ||
ON | ||
subq_21.metric_time__day = subq_30.metric_time__day | ||
GROUP BY | ||
metric_time__day | ||
) subq_31 |
Oops, something went wrong.