-
Notifications
You must be signed in to change notification settings - Fork 96
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
01d076f
commit 64398ac
Showing
65 changed files
with
19,773 additions
and
0 deletions.
There are no files selected for viewing
346 changes: 346 additions & 0 deletions
346
...metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_count_with_no_group_by__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
..._sql.py/SqlQueryPlan/BigQuery/test_conversion_count_with_no_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,63 @@ | ||
-- Combine Aggregated Outputs | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
COALESCE(MAX(subq_28.buys), 0) AS visit_buy_conversions | ||
FROM ( | ||
-- Read Elements From Semantic Model 'visits_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Pass Only Elements: | ||
-- ['visits'] | ||
-- Aggregate Measures | ||
SELECT | ||
SUM(1) AS visits | ||
FROM ***************************.fct_visits visits_source_src_10011 | ||
) subq_18 | ||
CROSS JOIN ( | ||
-- Find conversions for user within the range of 7 day | ||
-- Pass Only Elements: | ||
-- ['buys'] | ||
-- Aggregate Measures | ||
SELECT | ||
SUM(buys) AS buys | ||
FROM ( | ||
-- Dedupe the fanout with mf_internal_uuid in the conversion data set | ||
SELECT DISTINCT | ||
first_value(subq_21.visits) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC) AS visits | ||
, first_value(subq_21.ds__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC) AS ds__day | ||
, first_value(subq_21.user) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC) AS user | ||
, subq_24.mf_internal_uuid AS mf_internal_uuid | ||
, subq_24.buys AS buys | ||
FROM ( | ||
-- Read Elements From Semantic Model 'visits_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Pass Only Elements: | ||
-- ['visits', 'ds__day', 'user'] | ||
SELECT | ||
DATE_TRUNC(ds, day) AS ds__day | ||
, user_id AS user | ||
, 1 AS visits | ||
FROM ***************************.fct_visits visits_source_src_10011 | ||
) subq_21 | ||
INNER JOIN ( | ||
-- Read Elements From Semantic Model 'buys_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Add column with generated UUID | ||
SELECT | ||
DATE_TRUNC(ds, day) AS ds__day | ||
, user_id AS user | ||
, 1 AS buys | ||
, GENERATE_UUID() AS mf_internal_uuid | ||
FROM ***************************.fct_buys buys_source_src_10002 | ||
) subq_24 | ||
ON | ||
( | ||
subq_21.user = subq_24.user | ||
) AND ( | ||
( | ||
subq_21.ds__day <= subq_24.ds__day | ||
) AND ( | ||
subq_21.ds__day > DATE_SUB(CAST(subq_24.ds__day AS DATETIME), INTERVAL 7 day) | ||
) | ||
) | ||
) subq_25 | ||
) subq_28 |
355 changes: 355 additions & 0 deletions
355
...s/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_rate__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
...version_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_rate__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,83 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
visit__referrer_id | ||
, CAST(buys AS FLOAT64) / CAST(NULLIF(visits, 0) AS FLOAT64) AS visit_buy_conversion_rate | ||
FROM ( | ||
-- Combine Aggregated Outputs | ||
SELECT | ||
COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id) AS visit__referrer_id | ||
, MAX(subq_18.visits) AS visits | ||
, MAX(subq_28.buys) AS buys | ||
FROM ( | ||
-- Aggregate Measures | ||
SELECT | ||
visit__referrer_id | ||
, SUM(visits) AS visits | ||
FROM ( | ||
-- Read Elements From Semantic Model 'visits_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Pass Only Elements: | ||
-- ['visits', 'visit__referrer_id'] | ||
SELECT | ||
referrer_id AS visit__referrer_id | ||
, 1 AS visits | ||
FROM ***************************.fct_visits visits_source_src_10011 | ||
) subq_17 | ||
GROUP BY | ||
visit__referrer_id | ||
) subq_18 | ||
FULL OUTER JOIN ( | ||
-- Find conversions for user within the range of INF | ||
-- Pass Only Elements: | ||
-- ['buys', 'visit__referrer_id'] | ||
-- Aggregate Measures | ||
SELECT | ||
visit__referrer_id | ||
, SUM(buys) AS buys | ||
FROM ( | ||
-- Dedupe the fanout with mf_internal_uuid in the conversion data set | ||
SELECT DISTINCT | ||
first_value(subq_21.visits) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC) AS visits | ||
, first_value(subq_21.visit__referrer_id) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC) AS visit__referrer_id | ||
, first_value(subq_21.ds__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC) AS ds__day | ||
, first_value(subq_21.user) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC) AS user | ||
, subq_24.mf_internal_uuid AS mf_internal_uuid | ||
, subq_24.buys AS buys | ||
FROM ( | ||
-- Read Elements From Semantic Model 'visits_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Pass Only Elements: | ||
-- ['visits', 'visit__referrer_id', 'ds__day', 'user'] | ||
SELECT | ||
DATE_TRUNC(ds, day) AS ds__day | ||
, user_id AS user | ||
, referrer_id AS visit__referrer_id | ||
, 1 AS visits | ||
FROM ***************************.fct_visits visits_source_src_10011 | ||
) subq_21 | ||
INNER JOIN ( | ||
-- Read Elements From Semantic Model 'buys_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Add column with generated UUID | ||
SELECT | ||
DATE_TRUNC(ds, day) AS ds__day | ||
, user_id AS user | ||
, 1 AS buys | ||
, GENERATE_UUID() AS mf_internal_uuid | ||
FROM ***************************.fct_buys buys_source_src_10002 | ||
) subq_24 | ||
ON | ||
( | ||
subq_21.user = subq_24.user | ||
) AND ( | ||
(subq_21.ds__day <= subq_24.ds__day) | ||
) | ||
) subq_25 | ||
GROUP BY | ||
visit__referrer_id | ||
) subq_28 | ||
ON | ||
subq_18.visit__referrer_id = subq_28.visit__referrer_id | ||
GROUP BY | ||
visit__referrer_id | ||
) subq_29 |
Oops, something went wrong.