Skip to content

Commit

Permalink
Update other engine snapshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Nov 13, 2024
1 parent de6592d commit 69ed6a8
Show file tree
Hide file tree
Showing 72 changed files with 2,703 additions and 2,715 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@ sql_engine: BigQuery
---
-- Combine Aggregated Outputs
-- Compute Metrics via Expressions
SELECT
COALESCE(MAX(subq_28.buys), 0) AS visit_buy_conversions
FROM (
WITH sma_28019_cte AS (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
SELECT
DATETIME_TRUNC(ds, day) AS metric_time__day
, user_id AS user
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
)

SELECT
COALESCE(MAX(subq_27.buys), 0) AS visit_buy_conversions
FROM (
-- Read From CTE For node_id=sma_28019
-- Pass Only Elements: ['visits',]
-- Aggregate Measures
SELECT
SUM(1) AS visits
FROM ***************************.fct_visits visits_source_src_28000
SUM(visits) AS visits
FROM sma_28019_cte sma_28019_cte
) subq_18
CROSS JOIN (
-- Find conversions for user within the range of 7 day
Expand All @@ -26,42 +35,33 @@ CROSS JOIN (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
FIRST_VALUE(subq_21.visits) OVER (
FIRST_VALUE(sma_28019_cte.visits) OVER (
PARTITION BY
subq_24.user
, subq_24.metric_time__day
, subq_24.mf_internal_uuid
ORDER BY subq_21.metric_time__day DESC
subq_23.user
, subq_23.metric_time__day
, subq_23.mf_internal_uuid
ORDER BY sma_28019_cte.metric_time__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, FIRST_VALUE(subq_21.metric_time__day) OVER (
, FIRST_VALUE(sma_28019_cte.metric_time__day) OVER (
PARTITION BY
subq_24.user
, subq_24.metric_time__day
, subq_24.mf_internal_uuid
ORDER BY subq_21.metric_time__day DESC
subq_23.user
, subq_23.metric_time__day
, subq_23.mf_internal_uuid
ORDER BY sma_28019_cte.metric_time__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
, FIRST_VALUE(subq_21.user) OVER (
, FIRST_VALUE(sma_28019_cte.user) OVER (
PARTITION BY
subq_24.user
, subq_24.metric_time__day
, subq_24.mf_internal_uuid
ORDER BY subq_21.metric_time__day DESC
subq_23.user
, subq_23.metric_time__day
, subq_23.mf_internal_uuid
ORDER BY sma_28019_cte.metric_time__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', 'metric_time__day', 'user']
SELECT
DATETIME_TRUNC(ds, day) AS metric_time__day
, user_id AS user
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
) subq_21
, subq_23.mf_internal_uuid AS mf_internal_uuid
, subq_23.buys AS buys
FROM sma_28019_cte sma_28019_cte
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
Expand All @@ -72,16 +72,16 @@ CROSS JOIN (
, 1 AS buys
, GENERATE_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
) subq_24
) subq_23
ON
(
subq_21.user = subq_24.user
sma_28019_cte.user = subq_23.user
) AND (
(
subq_21.metric_time__day <= subq_24.metric_time__day
sma_28019_cte.metric_time__day <= subq_23.metric_time__day
) AND (
subq_21.metric_time__day > DATE_SUB(CAST(subq_24.metric_time__day AS DATETIME), INTERVAL 7 day)
sma_28019_cte.metric_time__day > DATE_SUB(CAST(subq_23.metric_time__day AS DATETIME), INTERVAL 7 day)
)
)
) subq_25
) subq_28
) subq_24
) subq_27
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,39 @@ docstring:
sql_engine: BigQuery
---
-- Compute Metrics via Expressions
WITH sma_28019_cte AS (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
SELECT
DATETIME_TRUNC(ds, day) AS metric_time__day
, user_id AS user
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
)

SELECT
metric_time__day
metric_time__day AS 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_27.metric_time__day, subq_40.metric_time__day) AS metric_time__day
COALESCE(subq_27.metric_time__day, subq_39.metric_time__day) AS metric_time__day
, COALESCE(MAX(subq_27.visits), 0) AS visits
, COALESCE(MAX(subq_40.buys), 0) AS buys
, COALESCE(MAX(subq_39.buys), 0) AS buys
FROM (
-- Join to Time Spine Dataset
SELECT
subq_26.ds AS metric_time__day
, subq_24.visits AS visits
FROM ***************************.mf_time_spine subq_26
LEFT OUTER JOIN (
-- Read From CTE For node_id=sma_28019
-- Pass Only Elements: ['visits', 'metric_time__day']
-- 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
DATETIME_TRUNC(ds, day) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
) subq_23
FROM sma_28019_cte sma_28019_cte
GROUP BY
metric_time__day
) subq_24
Expand All @@ -43,9 +47,9 @@ FROM (
FULL OUTER JOIN (
-- Join to Time Spine Dataset
SELECT
subq_39.ds AS metric_time__day
, subq_37.buys AS buys
FROM ***************************.mf_time_spine subq_39
subq_38.ds AS metric_time__day
, subq_36.buys AS buys
FROM ***************************.mf_time_spine subq_38
LEFT OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'metric_time__day']
Expand All @@ -56,42 +60,33 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
FIRST_VALUE(subq_30.visits) OVER (
FIRST_VALUE(sma_28019_cte.visits) OVER (
PARTITION BY
subq_33.user
, subq_33.metric_time__day
, subq_33.mf_internal_uuid
ORDER BY subq_30.metric_time__day DESC
subq_32.user
, subq_32.metric_time__day
, subq_32.mf_internal_uuid
ORDER BY sma_28019_cte.metric_time__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, FIRST_VALUE(subq_30.metric_time__day) OVER (
, FIRST_VALUE(sma_28019_cte.metric_time__day) OVER (
PARTITION BY
subq_33.user
, subq_33.metric_time__day
, subq_33.mf_internal_uuid
ORDER BY subq_30.metric_time__day DESC
subq_32.user
, subq_32.metric_time__day
, subq_32.mf_internal_uuid
ORDER BY sma_28019_cte.metric_time__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
, FIRST_VALUE(subq_30.user) OVER (
, FIRST_VALUE(sma_28019_cte.user) OVER (
PARTITION BY
subq_33.user
, subq_33.metric_time__day
, subq_33.mf_internal_uuid
ORDER BY subq_30.metric_time__day DESC
subq_32.user
, subq_32.metric_time__day
, subq_32.mf_internal_uuid
ORDER BY sma_28019_cte.metric_time__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
, subq_33.mf_internal_uuid AS mf_internal_uuid
, subq_33.buys AS buys
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
-- Pass Only Elements: ['visits', 'metric_time__day', 'user']
SELECT
DATETIME_TRUNC(ds, day) AS metric_time__day
, user_id AS user
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
) subq_30
, subq_32.mf_internal_uuid AS mf_internal_uuid
, subq_32.buys AS buys
FROM sma_28019_cte sma_28019_cte
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
Expand All @@ -102,26 +97,26 @@ FROM (
, 1 AS buys
, GENERATE_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
) subq_33
) subq_32
ON
(
subq_30.user = subq_33.user
sma_28019_cte.user = subq_32.user
) AND (
(
subq_30.metric_time__day <= subq_33.metric_time__day
sma_28019_cte.metric_time__day <= subq_32.metric_time__day
) AND (
subq_30.metric_time__day > DATE_SUB(CAST(subq_33.metric_time__day AS DATETIME), INTERVAL 7 day)
sma_28019_cte.metric_time__day > DATE_SUB(CAST(subq_32.metric_time__day AS DATETIME), INTERVAL 7 day)
)
)
) subq_34
) subq_33
GROUP BY
metric_time__day
) subq_37
) subq_36
ON
subq_39.ds = subq_37.metric_time__day
) subq_40
subq_38.ds = subq_36.metric_time__day
) subq_39
ON
subq_27.metric_time__day = subq_40.metric_time__day
subq_27.metric_time__day = subq_39.metric_time__day
GROUP BY
metric_time__day
) subq_41
) subq_40
Loading

0 comments on commit 69ed6a8

Please sign in to comment.