-
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.
- Loading branch information
1 parent
718c60f
commit ad8d233
Showing
24 changed files
with
5,790 additions
and
0 deletions.
There are no files selected for viewing
327 changes: 327 additions & 0 deletions
327
...custom_granularity.py/SqlPlan/BigQuery/test_custom_grain_in_metric_yaml_filter__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
...nularity.py/SqlPlan/BigQuery/test_custom_grain_in_metric_yaml_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,33 @@ | ||
test_name: test_custom_grain_in_metric_yaml_filter | ||
test_filename: test_custom_granularity.py | ||
sql_engine: BigQuery | ||
--- | ||
-- Constrain Output with WHERE | ||
-- Pass Only Elements: ['bookings', 'metric_time__day'] | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__day | ||
, SUM(bookings) AS bookings_on_first_alien_day | ||
FROM ( | ||
-- Metric Time Dimension 'ds' | ||
-- Join to Custom Granularity Dataset | ||
SELECT | ||
subq_6.ds__day AS metric_time__day | ||
, subq_6.bookings AS bookings | ||
, subq_7.alien_day AS metric_time__alien_day | ||
FROM ( | ||
-- Read Elements From Semantic Model 'bookings_source' | ||
SELECT | ||
1 AS bookings | ||
, DATETIME_TRUNC(ds, day) AS ds__day | ||
FROM ***************************.fct_bookings bookings_source_src_28000 | ||
) subq_6 | ||
LEFT OUTER JOIN | ||
***************************.mf_time_spine subq_7 | ||
ON | ||
subq_6.ds__day = subq_7.ds | ||
) subq_8 | ||
WHERE metric_time__alien_day | ||
GROUP BY | ||
metric_time__day |
512 changes: 512 additions & 0 deletions
512
...rity.py/SqlPlan/BigQuery/test_custom_offset_window_with_filter_not_in_group_by__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
...lPlan/BigQuery/test_custom_offset_window_with_filter_not_in_group_by__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,93 @@ | ||
test_name: test_custom_offset_window_with_filter_not_in_group_by | ||
test_filename: test_custom_granularity.py | ||
sql_engine: BigQuery | ||
--- | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__day | ||
, bookings AS bookings_offset_one_alien_day | ||
FROM ( | ||
-- Constrain Output with WHERE | ||
-- Pass Only Elements: ['bookings', 'metric_time__day'] | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__day | ||
, SUM(bookings) AS bookings | ||
FROM ( | ||
-- Join to Time Spine Dataset | ||
SELECT | ||
subq_26.ds__day__lead AS metric_time__day | ||
, subq_22.metric_time__month AS metric_time__month | ||
, subq_22.bookings AS bookings | ||
FROM ( | ||
-- Offset Base Granularity By Custom Granularity Period(s) | ||
WITH cte_6 AS ( | ||
-- Read From Time Spine 'mf_time_spine' | ||
-- Get Custom Granularity Bounds | ||
SELECT | ||
ds AS ds__day | ||
, alien_day AS ds__alien_day | ||
, FIRST_VALUE(ds) OVER ( | ||
PARTITION BY alien_day | ||
ORDER BY ds | ||
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | ||
) AS ds__day__first_value | ||
, LAST_VALUE(ds) OVER ( | ||
PARTITION BY alien_day | ||
ORDER BY ds | ||
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | ||
) AS ds__day__last_value | ||
, ROW_NUMBER() OVER ( | ||
PARTITION BY alien_day | ||
ORDER BY ds | ||
) AS ds__day__row_number | ||
FROM ***************************.mf_time_spine time_spine_src_28006 | ||
) | ||
|
||
SELECT | ||
cte_6.ds__day AS ds__day | ||
, CASE | ||
WHEN DATE_ADD(CAST(subq_25.ds__day__first_value__lead AS DATETIME), INTERVAL cte_6.ds__day__row_number - 1 day) <= subq_25.ds__day__last_value__lead | ||
THEN DATE_ADD(CAST(subq_25.ds__day__first_value__lead AS DATETIME), INTERVAL cte_6.ds__day__row_number - 1 day) | ||
ELSE NULL | ||
END AS ds__day__lead | ||
FROM cte_6 cte_6 | ||
INNER JOIN ( | ||
-- Offset Custom Granularity Bounds | ||
SELECT | ||
ds__alien_day | ||
, LEAD(ds__day__first_value, 1) OVER (ORDER BY ds__alien_day) AS ds__day__first_value__lead | ||
, LEAD(ds__day__last_value, 1) OVER (ORDER BY ds__alien_day) AS ds__day__last_value__lead | ||
FROM ( | ||
-- Get Unique Rows for Custom Granularity Bounds | ||
SELECT | ||
ds__alien_day | ||
, ds__day__first_value | ||
, ds__day__last_value | ||
FROM cte_6 cte_6 | ||
GROUP BY | ||
ds__alien_day | ||
, ds__day__first_value | ||
, ds__day__last_value | ||
) subq_24 | ||
) subq_25 | ||
ON | ||
cte_6.ds__alien_day = subq_25.ds__alien_day | ||
) subq_26 | ||
INNER JOIN ( | ||
-- Read Elements From Semantic Model 'bookings_source' | ||
-- Metric Time Dimension 'ds' | ||
SELECT | ||
DATETIME_TRUNC(ds, day) AS metric_time__day | ||
, DATETIME_TRUNC(ds, month) AS metric_time__month | ||
, 1 AS bookings | ||
FROM ***************************.fct_bookings bookings_source_src_28000 | ||
) subq_22 | ||
ON | ||
subq_26.ds__day = subq_22.metric_time__day | ||
) subq_29 | ||
WHERE metric_time__month = '2020-01-01' | ||
GROUP BY | ||
metric_time__day | ||
) subq_33 |
Oops, something went wrong.