-
Notifications
You must be signed in to change notification settings - Fork 98
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
571e03c
commit 72912f4
Showing
84 changed files
with
10,590 additions
and
0 deletions.
There are no files selected for viewing
173 changes: 173 additions & 0 deletions
173
...endering.py/SqlQueryPlan/BigQuery/test_all_time_metric_with_non_default_grains__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,173 @@ | ||
-- Re-aggregate Metrics via Window Functions | ||
SELECT | ||
subq_8.metric_time__week | ||
, subq_8.metric_time__quarter | ||
, subq_8.revenue_all_time | ||
FROM ( | ||
SELECT | ||
subq_7.metric_time__week | ||
, subq_7.metric_time__quarter | ||
, FIRST_VALUE(subq_7.revenue_all_time) OVER ( | ||
PARTITION BY | ||
subq_7.metric_time__week | ||
, subq_7.metric_time__quarter | ||
ORDER BY subq_7.metric_time__day | ||
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | ||
) AS revenue_all_time | ||
FROM ( | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_6.metric_time__day | ||
, subq_6.metric_time__week | ||
, subq_6.metric_time__quarter | ||
, subq_6.txn_revenue AS revenue_all_time | ||
FROM ( | ||
-- Aggregate Measures | ||
SELECT | ||
subq_5.metric_time__day | ||
, subq_5.metric_time__week | ||
, subq_5.metric_time__quarter | ||
, SUM(subq_5.txn_revenue) AS txn_revenue | ||
FROM ( | ||
-- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__quarter', 'metric_time__day'] | ||
SELECT | ||
subq_4.metric_time__day | ||
, subq_4.metric_time__week | ||
, subq_4.metric_time__quarter | ||
, subq_4.txn_revenue | ||
FROM ( | ||
-- Join Self Over Time Range | ||
SELECT | ||
subq_2.metric_time__day AS metric_time__day | ||
, subq_2.metric_time__week AS metric_time__week | ||
, subq_2.metric_time__quarter AS metric_time__quarter | ||
, subq_1.ds__day AS ds__day | ||
, subq_1.ds__week AS ds__week | ||
, subq_1.ds__month AS ds__month | ||
, subq_1.ds__quarter AS ds__quarter | ||
, subq_1.ds__year AS ds__year | ||
, subq_1.ds__extract_year AS ds__extract_year | ||
, subq_1.ds__extract_quarter AS ds__extract_quarter | ||
, subq_1.ds__extract_month AS ds__extract_month | ||
, subq_1.ds__extract_day AS ds__extract_day | ||
, subq_1.ds__extract_dow AS ds__extract_dow | ||
, subq_1.ds__extract_doy AS ds__extract_doy | ||
, subq_1.revenue_instance__ds__day AS revenue_instance__ds__day | ||
, subq_1.revenue_instance__ds__week AS revenue_instance__ds__week | ||
, subq_1.revenue_instance__ds__month AS revenue_instance__ds__month | ||
, subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter | ||
, subq_1.revenue_instance__ds__year AS revenue_instance__ds__year | ||
, subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year | ||
, subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter | ||
, subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month | ||
, subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day | ||
, subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow | ||
, subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy | ||
, subq_1.metric_time__month AS metric_time__month | ||
, subq_1.metric_time__year AS metric_time__year | ||
, subq_1.metric_time__extract_year AS metric_time__extract_year | ||
, subq_1.metric_time__extract_quarter AS metric_time__extract_quarter | ||
, subq_1.metric_time__extract_month AS metric_time__extract_month | ||
, subq_1.metric_time__extract_day AS metric_time__extract_day | ||
, subq_1.metric_time__extract_dow AS metric_time__extract_dow | ||
, subq_1.metric_time__extract_doy AS metric_time__extract_doy | ||
, subq_1.user AS user | ||
, subq_1.revenue_instance__user AS revenue_instance__user | ||
, subq_1.txn_revenue AS txn_revenue | ||
FROM ( | ||
-- Time Spine | ||
SELECT | ||
subq_3.ds AS metric_time__day | ||
, DATETIME_TRUNC(subq_3.ds, isoweek) AS metric_time__week | ||
, DATETIME_TRUNC(subq_3.ds, quarter) AS metric_time__quarter | ||
FROM ***************************.mf_time_spine subq_3 | ||
GROUP BY | ||
metric_time__day | ||
, metric_time__week | ||
, metric_time__quarter | ||
) subq_2 | ||
INNER JOIN ( | ||
-- Metric Time Dimension 'ds' | ||
SELECT | ||
subq_0.ds__day | ||
, subq_0.ds__week | ||
, subq_0.ds__month | ||
, subq_0.ds__quarter | ||
, subq_0.ds__year | ||
, subq_0.ds__extract_year | ||
, subq_0.ds__extract_quarter | ||
, subq_0.ds__extract_month | ||
, subq_0.ds__extract_day | ||
, subq_0.ds__extract_dow | ||
, subq_0.ds__extract_doy | ||
, subq_0.revenue_instance__ds__day | ||
, subq_0.revenue_instance__ds__week | ||
, subq_0.revenue_instance__ds__month | ||
, subq_0.revenue_instance__ds__quarter | ||
, subq_0.revenue_instance__ds__year | ||
, subq_0.revenue_instance__ds__extract_year | ||
, subq_0.revenue_instance__ds__extract_quarter | ||
, subq_0.revenue_instance__ds__extract_month | ||
, subq_0.revenue_instance__ds__extract_day | ||
, subq_0.revenue_instance__ds__extract_dow | ||
, subq_0.revenue_instance__ds__extract_doy | ||
, subq_0.ds__day AS metric_time__day | ||
, subq_0.ds__week AS metric_time__week | ||
, subq_0.ds__month AS metric_time__month | ||
, subq_0.ds__quarter AS metric_time__quarter | ||
, subq_0.ds__year AS metric_time__year | ||
, subq_0.ds__extract_year AS metric_time__extract_year | ||
, subq_0.ds__extract_quarter AS metric_time__extract_quarter | ||
, subq_0.ds__extract_month AS metric_time__extract_month | ||
, subq_0.ds__extract_day AS metric_time__extract_day | ||
, subq_0.ds__extract_dow AS metric_time__extract_dow | ||
, subq_0.ds__extract_doy AS metric_time__extract_doy | ||
, subq_0.user | ||
, subq_0.revenue_instance__user | ||
, subq_0.txn_revenue | ||
FROM ( | ||
-- Read Elements From Semantic Model 'revenue' | ||
SELECT | ||
revenue_src_28000.revenue AS txn_revenue | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, day) AS ds__day | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, isoweek) AS ds__week | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, month) AS ds__month | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, quarter) AS ds__quarter | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, year) AS ds__year | ||
, EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year | ||
, EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter | ||
, EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month | ||
, EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day | ||
, IF(EXTRACT(dayofweek FROM revenue_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM revenue_src_28000.created_at) - 1) AS ds__extract_dow | ||
, EXTRACT(dayofyear FROM revenue_src_28000.created_at) AS ds__extract_doy | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, day) AS revenue_instance__ds__day | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, isoweek) AS revenue_instance__ds__week | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, month) AS revenue_instance__ds__month | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, quarter) AS revenue_instance__ds__quarter | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, year) AS revenue_instance__ds__year | ||
, EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year | ||
, EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter | ||
, EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month | ||
, EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day | ||
, IF(EXTRACT(dayofweek FROM revenue_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM revenue_src_28000.created_at) - 1) AS revenue_instance__ds__extract_dow | ||
, EXTRACT(dayofyear FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy | ||
, revenue_src_28000.user_id AS user | ||
, revenue_src_28000.user_id AS revenue_instance__user | ||
FROM ***************************.fct_revenue revenue_src_28000 | ||
) subq_0 | ||
) subq_1 | ||
ON | ||
(subq_1.metric_time__day <= subq_2.metric_time__day) | ||
) subq_4 | ||
) subq_5 | ||
GROUP BY | ||
metric_time__day | ||
, metric_time__week | ||
, metric_time__quarter | ||
) subq_6 | ||
) subq_7 | ||
) subq_8 | ||
GROUP BY | ||
metric_time__week | ||
, metric_time__quarter | ||
, revenue_all_time |
54 changes: 54 additions & 0 deletions
54
...y/SqlQueryPlan/BigQuery/test_all_time_metric_with_non_default_grains__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,54 @@ | ||
-- Re-aggregate Metrics via Window Functions | ||
SELECT | ||
metric_time__week | ||
, metric_time__quarter | ||
, revenue_all_time | ||
FROM ( | ||
SELECT | ||
metric_time__week | ||
, metric_time__quarter | ||
, FIRST_VALUE(revenue_all_time) OVER ( | ||
PARTITION BY | ||
metric_time__week | ||
, metric_time__quarter | ||
ORDER BY metric_time__day | ||
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | ||
) AS revenue_all_time | ||
FROM ( | ||
-- Join Self Over Time Range | ||
-- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__quarter', 'metric_time__day'] | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_11.metric_time__day AS metric_time__day | ||
, subq_11.metric_time__week AS metric_time__week | ||
, subq_11.metric_time__quarter AS metric_time__quarter | ||
, SUM(revenue_src_28000.revenue) AS revenue_all_time | ||
FROM ( | ||
-- Time Spine | ||
SELECT | ||
ds AS metric_time__day | ||
, DATETIME_TRUNC(ds, isoweek) AS metric_time__week | ||
, DATETIME_TRUNC(ds, quarter) AS metric_time__quarter | ||
FROM ***************************.mf_time_spine subq_12 | ||
GROUP BY | ||
metric_time__day | ||
, metric_time__week | ||
, metric_time__quarter | ||
) subq_11 | ||
INNER JOIN | ||
***************************.fct_revenue revenue_src_28000 | ||
ON | ||
( | ||
DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_11.metric_time__day | ||
) | ||
GROUP BY | ||
metric_time__day | ||
, metric_time__week | ||
, metric_time__quarter | ||
) subq_16 | ||
) subq_17 | ||
GROUP BY | ||
metric_time__week | ||
, metric_time__quarter | ||
, revenue_all_time |
162 changes: 162 additions & 0 deletions
162
...ndering.py/SqlQueryPlan/BigQuery/test_cumulative_metric_with_non_default_grain__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,162 @@ | ||
-- Re-aggregate Metrics via Window Functions | ||
SELECT | ||
subq_8.metric_time__week | ||
, subq_8.revenue_all_time | ||
FROM ( | ||
SELECT | ||
subq_7.metric_time__week | ||
, FIRST_VALUE(subq_7.revenue_all_time) OVER ( | ||
PARTITION BY subq_7.metric_time__week | ||
ORDER BY subq_7.metric_time__day | ||
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | ||
) AS revenue_all_time | ||
FROM ( | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_6.metric_time__day | ||
, subq_6.metric_time__week | ||
, subq_6.txn_revenue AS revenue_all_time | ||
FROM ( | ||
-- Aggregate Measures | ||
SELECT | ||
subq_5.metric_time__day | ||
, subq_5.metric_time__week | ||
, SUM(subq_5.txn_revenue) AS txn_revenue | ||
FROM ( | ||
-- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] | ||
SELECT | ||
subq_4.metric_time__day | ||
, subq_4.metric_time__week | ||
, subq_4.txn_revenue | ||
FROM ( | ||
-- Join Self Over Time Range | ||
SELECT | ||
subq_2.metric_time__day AS metric_time__day | ||
, subq_2.metric_time__week AS metric_time__week | ||
, subq_1.ds__day AS ds__day | ||
, subq_1.ds__week AS ds__week | ||
, subq_1.ds__month AS ds__month | ||
, subq_1.ds__quarter AS ds__quarter | ||
, subq_1.ds__year AS ds__year | ||
, subq_1.ds__extract_year AS ds__extract_year | ||
, subq_1.ds__extract_quarter AS ds__extract_quarter | ||
, subq_1.ds__extract_month AS ds__extract_month | ||
, subq_1.ds__extract_day AS ds__extract_day | ||
, subq_1.ds__extract_dow AS ds__extract_dow | ||
, subq_1.ds__extract_doy AS ds__extract_doy | ||
, subq_1.revenue_instance__ds__day AS revenue_instance__ds__day | ||
, subq_1.revenue_instance__ds__week AS revenue_instance__ds__week | ||
, subq_1.revenue_instance__ds__month AS revenue_instance__ds__month | ||
, subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter | ||
, subq_1.revenue_instance__ds__year AS revenue_instance__ds__year | ||
, subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year | ||
, subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter | ||
, subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month | ||
, subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day | ||
, subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow | ||
, subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy | ||
, subq_1.metric_time__month AS metric_time__month | ||
, subq_1.metric_time__quarter AS metric_time__quarter | ||
, subq_1.metric_time__year AS metric_time__year | ||
, subq_1.metric_time__extract_year AS metric_time__extract_year | ||
, subq_1.metric_time__extract_quarter AS metric_time__extract_quarter | ||
, subq_1.metric_time__extract_month AS metric_time__extract_month | ||
, subq_1.metric_time__extract_day AS metric_time__extract_day | ||
, subq_1.metric_time__extract_dow AS metric_time__extract_dow | ||
, subq_1.metric_time__extract_doy AS metric_time__extract_doy | ||
, subq_1.user AS user | ||
, subq_1.revenue_instance__user AS revenue_instance__user | ||
, subq_1.txn_revenue AS txn_revenue | ||
FROM ( | ||
-- Time Spine | ||
SELECT | ||
subq_3.ds AS metric_time__day | ||
, DATETIME_TRUNC(subq_3.ds, isoweek) AS metric_time__week | ||
FROM ***************************.mf_time_spine subq_3 | ||
GROUP BY | ||
metric_time__day | ||
, metric_time__week | ||
) subq_2 | ||
INNER JOIN ( | ||
-- Metric Time Dimension 'ds' | ||
SELECT | ||
subq_0.ds__day | ||
, subq_0.ds__week | ||
, subq_0.ds__month | ||
, subq_0.ds__quarter | ||
, subq_0.ds__year | ||
, subq_0.ds__extract_year | ||
, subq_0.ds__extract_quarter | ||
, subq_0.ds__extract_month | ||
, subq_0.ds__extract_day | ||
, subq_0.ds__extract_dow | ||
, subq_0.ds__extract_doy | ||
, subq_0.revenue_instance__ds__day | ||
, subq_0.revenue_instance__ds__week | ||
, subq_0.revenue_instance__ds__month | ||
, subq_0.revenue_instance__ds__quarter | ||
, subq_0.revenue_instance__ds__year | ||
, subq_0.revenue_instance__ds__extract_year | ||
, subq_0.revenue_instance__ds__extract_quarter | ||
, subq_0.revenue_instance__ds__extract_month | ||
, subq_0.revenue_instance__ds__extract_day | ||
, subq_0.revenue_instance__ds__extract_dow | ||
, subq_0.revenue_instance__ds__extract_doy | ||
, subq_0.ds__day AS metric_time__day | ||
, subq_0.ds__week AS metric_time__week | ||
, subq_0.ds__month AS metric_time__month | ||
, subq_0.ds__quarter AS metric_time__quarter | ||
, subq_0.ds__year AS metric_time__year | ||
, subq_0.ds__extract_year AS metric_time__extract_year | ||
, subq_0.ds__extract_quarter AS metric_time__extract_quarter | ||
, subq_0.ds__extract_month AS metric_time__extract_month | ||
, subq_0.ds__extract_day AS metric_time__extract_day | ||
, subq_0.ds__extract_dow AS metric_time__extract_dow | ||
, subq_0.ds__extract_doy AS metric_time__extract_doy | ||
, subq_0.user | ||
, subq_0.revenue_instance__user | ||
, subq_0.txn_revenue | ||
FROM ( | ||
-- Read Elements From Semantic Model 'revenue' | ||
SELECT | ||
revenue_src_28000.revenue AS txn_revenue | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, day) AS ds__day | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, isoweek) AS ds__week | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, month) AS ds__month | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, quarter) AS ds__quarter | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, year) AS ds__year | ||
, EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year | ||
, EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter | ||
, EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month | ||
, EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day | ||
, IF(EXTRACT(dayofweek FROM revenue_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM revenue_src_28000.created_at) - 1) AS ds__extract_dow | ||
, EXTRACT(dayofyear FROM revenue_src_28000.created_at) AS ds__extract_doy | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, day) AS revenue_instance__ds__day | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, isoweek) AS revenue_instance__ds__week | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, month) AS revenue_instance__ds__month | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, quarter) AS revenue_instance__ds__quarter | ||
, DATETIME_TRUNC(revenue_src_28000.created_at, year) AS revenue_instance__ds__year | ||
, EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year | ||
, EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter | ||
, EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month | ||
, EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day | ||
, IF(EXTRACT(dayofweek FROM revenue_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM revenue_src_28000.created_at) - 1) AS revenue_instance__ds__extract_dow | ||
, EXTRACT(dayofyear FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy | ||
, revenue_src_28000.user_id AS user | ||
, revenue_src_28000.user_id AS revenue_instance__user | ||
FROM ***************************.fct_revenue revenue_src_28000 | ||
) subq_0 | ||
) subq_1 | ||
ON | ||
(subq_1.metric_time__day <= subq_2.metric_time__day) | ||
) subq_4 | ||
) subq_5 | ||
GROUP BY | ||
metric_time__day | ||
, metric_time__week | ||
) subq_6 | ||
) subq_7 | ||
) subq_8 | ||
GROUP BY | ||
metric_time__week | ||
, revenue_all_time |
Oops, something went wrong.