-
Notifications
You must be signed in to change notification settings - Fork 94
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
42f0421
commit 3cddd91
Showing
56 changed files
with
3,661 additions
and
0 deletions.
There are no files selected for viewing
383 changes: 383 additions & 0 deletions
383
...n_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
...endering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_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,94 @@ | ||
-- Combine Aggregated Outputs | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
CAST(MAX(subq_32.buys) AS FLOAT64) / CAST(NULLIF(MAX(subq_22.visits), 0) AS FLOAT64) AS visit_buy_conversion_rate | ||
FROM ( | ||
-- Constrain Output with WHERE | ||
-- Pass Only Elements: ['visits',] | ||
-- Aggregate Measures | ||
SELECT | ||
SUM(visits) AS visits | ||
FROM ( | ||
-- Read Elements From Semantic Model 'visits_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Pass Only Elements: ['visits', 'metric_time__day'] | ||
SELECT | ||
DATETIME_TRUNC(ds, day) AS metric_time__day | ||
, 1 AS visits | ||
FROM ***************************.fct_visits visits_source_src_28000 | ||
) subq_19 | ||
WHERE metric_time__day = '2020-01-01' | ||
) subq_22 | ||
CROSS JOIN ( | ||
-- Find conversions for user within the range of INF | ||
-- 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_25.visits) OVER ( | ||
PARTITION BY | ||
subq_28.user | ||
, subq_28.ds__day | ||
, subq_28.mf_internal_uuid | ||
ORDER BY subq_25.ds__day DESC | ||
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | ||
) AS visits | ||
, FIRST_VALUE(subq_25.ds__day) OVER ( | ||
PARTITION BY | ||
subq_28.user | ||
, subq_28.ds__day | ||
, subq_28.mf_internal_uuid | ||
ORDER BY subq_25.ds__day DESC | ||
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | ||
) AS ds__day | ||
, FIRST_VALUE(subq_25.metric_time__day) OVER ( | ||
PARTITION BY | ||
subq_28.user | ||
, subq_28.ds__day | ||
, subq_28.mf_internal_uuid | ||
ORDER BY subq_25.ds__day DESC | ||
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | ||
) AS metric_time__day | ||
, FIRST_VALUE(subq_25.user) OVER ( | ||
PARTITION BY | ||
subq_28.user | ||
, subq_28.ds__day | ||
, subq_28.mf_internal_uuid | ||
ORDER BY subq_25.ds__day DESC | ||
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | ||
) AS user | ||
, subq_28.mf_internal_uuid AS mf_internal_uuid | ||
, subq_28.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 | ||
DATETIME_TRUNC(ds, day) AS ds__day | ||
, DATETIME_TRUNC(ds, day) AS metric_time__day | ||
, user_id AS user | ||
, 1 AS visits | ||
FROM ***************************.fct_visits visits_source_src_28000 | ||
) subq_25 | ||
INNER JOIN ( | ||
-- Read Elements From Semantic Model 'buys_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Add column with generated UUID | ||
SELECT | ||
DATETIME_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_28 | ||
ON | ||
( | ||
subq_25.user = subq_28.user | ||
) AND ( | ||
(subq_25.ds__day <= subq_28.ds__day) | ||
) | ||
) subq_29 | ||
) subq_32 |
Oops, something went wrong.