-
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.
- Loading branch information
1 parent
9461ee6
commit f0f4614
Showing
57 changed files
with
12,602 additions
and
0 deletions.
There are no files selected for viewing
360 changes: 360 additions & 0 deletions
360
...trics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_fill_nulls_with_0__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
...ql.py/SqlQueryPlan/BigQuery/test_conversion_metric_fill_nulls_with_0__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,84 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__day | ||
, CAST(buys AS FLOAT64) / CAST(NULLIF(visits, 0) AS FLOAT64) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 | ||
FROM ( | ||
-- Combine Aggregated Outputs | ||
SELECT | ||
COALESCE(subq_18.metric_time__day, subq_28.metric_time__day) AS metric_time__day | ||
, COALESCE(MAX(subq_18.visits), 0) AS visits | ||
, COALESCE(MAX(subq_28.buys), 0) AS buys | ||
FROM ( | ||
-- Aggregate Measures | ||
SELECT | ||
metric_time__day | ||
, SUM(visits) AS visits | ||
FROM ( | ||
-- Read Elements From Semantic Model 'visits_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Pass Only Elements: ['visits', 'metric_time__day'] | ||
SELECT | ||
DATE_TRUNC(ds, day) AS metric_time__day | ||
, 1 AS visits | ||
FROM ***************************.fct_visits visits_source_src_28000 | ||
) subq_17 | ||
GROUP BY | ||
metric_time__day | ||
) subq_18 | ||
FULL OUTER JOIN ( | ||
-- Find conversions for user within the range of 7 day | ||
-- Pass Only Elements: ['buys', 'metric_time__day'] | ||
-- Aggregate Measures | ||
SELECT | ||
metric_time__day | ||
, 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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) 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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day | ||
, first_value(subq_21.metric_time__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS metric_time__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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) 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', 'metric_time__day', 'user'] | ||
SELECT | ||
DATE_TRUNC(ds, day) AS ds__day | ||
, DATE_TRUNC(ds, day) AS metric_time__day | ||
, user_id AS user | ||
, 1 AS visits | ||
FROM ***************************.fct_visits visits_source_src_28000 | ||
) 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_28000 | ||
) 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 | ||
GROUP BY | ||
metric_time__day | ||
) subq_28 | ||
ON | ||
subq_18.metric_time__day = subq_28.metric_time__day | ||
GROUP BY | ||
metric_time__day | ||
) subq_29 |
360 changes: 360 additions & 0 deletions
360
...ics_to_sql.py/SqlQueryPlan/Databricks/test_conversion_metric_fill_nulls_with_0__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
....py/SqlQueryPlan/Databricks/test_conversion_metric_fill_nulls_with_0__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,84 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__day | ||
, CAST(buys AS DOUBLE) / CAST(NULLIF(visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 | ||
FROM ( | ||
-- Combine Aggregated Outputs | ||
SELECT | ||
COALESCE(subq_18.metric_time__day, subq_28.metric_time__day) AS metric_time__day | ||
, COALESCE(MAX(subq_18.visits), 0) AS visits | ||
, COALESCE(MAX(subq_28.buys), 0) AS buys | ||
FROM ( | ||
-- Aggregate Measures | ||
SELECT | ||
metric_time__day | ||
, SUM(visits) AS visits | ||
FROM ( | ||
-- Read Elements From Semantic Model 'visits_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Pass Only Elements: ['visits', 'metric_time__day'] | ||
SELECT | ||
DATE_TRUNC('day', ds) AS metric_time__day | ||
, 1 AS visits | ||
FROM ***************************.fct_visits visits_source_src_28000 | ||
) subq_17 | ||
GROUP BY | ||
metric_time__day | ||
) subq_18 | ||
FULL OUTER JOIN ( | ||
-- Find conversions for user within the range of 7 day | ||
-- Pass Only Elements: ['buys', 'metric_time__day'] | ||
-- Aggregate Measures | ||
SELECT | ||
metric_time__day | ||
, 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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) 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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day | ||
, first_value(subq_21.metric_time__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS metric_time__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 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) 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', 'metric_time__day', 'user'] | ||
SELECT | ||
DATE_TRUNC('day', ds) AS ds__day | ||
, DATE_TRUNC('day', ds) AS metric_time__day | ||
, user_id AS user | ||
, 1 AS visits | ||
FROM ***************************.fct_visits visits_source_src_28000 | ||
) subq_21 | ||
INNER JOIN ( | ||
-- Read Elements From Semantic Model 'buys_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Add column with generated UUID | ||
SELECT | ||
DATE_TRUNC('day', ds) AS ds__day | ||
, user_id AS user | ||
, 1 AS buys | ||
, UUID() AS mf_internal_uuid | ||
FROM ***************************.fct_buys buys_source_src_28000 | ||
) subq_24 | ||
ON | ||
( | ||
subq_21.user = subq_24.user | ||
) AND ( | ||
( | ||
subq_21.ds__day <= subq_24.ds__day | ||
) AND ( | ||
subq_21.ds__day > DATEADD(day, -7, subq_24.ds__day) | ||
) | ||
) | ||
) subq_25 | ||
GROUP BY | ||
metric_time__day | ||
) subq_28 | ||
ON | ||
subq_18.metric_time__day = subq_28.metric_time__day | ||
GROUP BY | ||
COALESCE(subq_18.metric_time__day, subq_28.metric_time__day) | ||
) subq_29 |
Oops, something went wrong.