Skip to content

Commit

Permalink
Update snapshots for other SQL engines.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Dec 11, 2024
1 parent db0165a commit 3215b65
Show file tree
Hide file tree
Showing 228 changed files with 8,602 additions and 8,296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ docstring:
sql_engine: BigQuery
---
-- Compute Metrics via Expressions
WITH sma_0_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
FROM (
-- Combine Aggregated Outputs
SELECT
COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
COALESCE(subq_21.metric_time__day, subq_31.metric_time__day) AS metric_time__day
, MAX(subq_21.visits) AS visits
, MAX(subq_32.buys) AS buys
, MAX(subq_31.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'metric_time__day']
Expand All @@ -22,12 +32,12 @@ FROM (
metric_time__day
, SUM(visits) AS visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
-- Read From CTE For node_id=sma_0
SELECT
DATETIME_TRUNC(ds, day) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
metric_time__day
, sma_0_cte.user
, visits
FROM sma_0_cte sma_0_cte
) subq_18
WHERE metric_time__day = '2020-01-01'
GROUP BY
Expand All @@ -43,50 +53,49 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
FIRST_VALUE(subq_25.visits) OVER (
FIRST_VALUE(subq_24.visits) OVER (
PARTITION BY
subq_28.user
, subq_28.metric_time__day
, subq_28.mf_internal_uuid
ORDER BY subq_25.metric_time__day DESC
subq_27.user
, subq_27.metric_time__day
, subq_27.mf_internal_uuid
ORDER BY subq_24.metric_time__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, FIRST_VALUE(subq_25.metric_time__day) OVER (
, FIRST_VALUE(subq_24.metric_time__day) OVER (
PARTITION BY
subq_28.user
, subq_28.metric_time__day
, subq_28.mf_internal_uuid
ORDER BY subq_25.metric_time__day DESC
subq_27.user
, subq_27.metric_time__day
, subq_27.mf_internal_uuid
ORDER BY subq_24.metric_time__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
, FIRST_VALUE(subq_25.user) OVER (
, FIRST_VALUE(subq_24.user) OVER (
PARTITION BY
subq_28.user
, subq_28.metric_time__day
, subq_28.mf_internal_uuid
ORDER BY subq_25.metric_time__day DESC
subq_27.user
, subq_27.metric_time__day
, subq_27.mf_internal_uuid
ORDER BY subq_24.metric_time__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
, subq_27.mf_internal_uuid AS mf_internal_uuid
, subq_27.buys AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'metric_time__day', 'user']
SELECT
metric_time__day
, subq_23.user
, subq_22.user
, visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
-- Read From CTE For node_id=sma_0
SELECT
DATETIME_TRUNC(ds, day) AS metric_time__day
, user_id AS user
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
) subq_23
metric_time__day
, sma_0_cte.user
, visits
FROM sma_0_cte sma_0_cte
) subq_22
WHERE metric_time__day = '2020-01-01'
) subq_25
) subq_24
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
Expand All @@ -97,19 +106,19 @@ FROM (
, 1 AS buys
, GENERATE_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
) subq_28
) subq_27
ON
(
subq_25.user = subq_28.user
subq_24.user = subq_27.user
) AND (
(subq_25.metric_time__day <= subq_28.metric_time__day)
(subq_24.metric_time__day <= subq_27.metric_time__day)
)
) subq_29
) subq_28
GROUP BY
metric_time__day
) subq_32
) subq_31
ON
subq_21.metric_time__day = subq_32.metric_time__day
subq_21.metric_time__day = subq_31.metric_time__day
GROUP BY
metric_time__day
) subq_33
) subq_32
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ docstring:
sql_engine: BigQuery
---
-- Compute Metrics via Expressions
WITH sma_0_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
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
)

SELECT
metric_time__day
, visit__referrer_id
metric_time__day AS metric_time__day
, visit__referrer_id AS 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_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
, COALESCE(subq_21.visit__referrer_id, subq_32.visit__referrer_id) AS visit__referrer_id
COALESCE(subq_21.metric_time__day, subq_31.metric_time__day) AS metric_time__day
, COALESCE(subq_21.visit__referrer_id, subq_31.visit__referrer_id) AS visit__referrer_id
, MAX(subq_21.visits) AS visits
, MAX(subq_32.buys) AS buys
, MAX(subq_31.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'metric_time__day']
Expand All @@ -25,13 +36,13 @@ FROM (
, visit__referrer_id
, SUM(visits) AS visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
-- Read From CTE For node_id=sma_0
SELECT
DATETIME_TRUNC(ds, day) AS metric_time__day
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
metric_time__day
, sma_0_cte.user
, visit__referrer_id
, visits
FROM sma_0_cte sma_0_cte
) subq_18
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
Expand All @@ -49,60 +60,59 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
FIRST_VALUE(subq_25.visits) OVER (
FIRST_VALUE(subq_24.visits) OVER (
PARTITION BY
subq_28.user
, subq_28.metric_time__day
, subq_28.mf_internal_uuid
ORDER BY subq_25.metric_time__day DESC
subq_27.user
, subq_27.metric_time__day
, subq_27.mf_internal_uuid
ORDER BY subq_24.metric_time__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, FIRST_VALUE(subq_25.visit__referrer_id) OVER (
, FIRST_VALUE(subq_24.visit__referrer_id) OVER (
PARTITION BY
subq_28.user
, subq_28.metric_time__day
, subq_28.mf_internal_uuid
ORDER BY subq_25.metric_time__day DESC
subq_27.user
, subq_27.metric_time__day
, subq_27.mf_internal_uuid
ORDER BY subq_24.metric_time__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
, FIRST_VALUE(subq_25.metric_time__day) OVER (
, FIRST_VALUE(subq_24.metric_time__day) OVER (
PARTITION BY
subq_28.user
, subq_28.metric_time__day
, subq_28.mf_internal_uuid
ORDER BY subq_25.metric_time__day DESC
subq_27.user
, subq_27.metric_time__day
, subq_27.mf_internal_uuid
ORDER BY subq_24.metric_time__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
, FIRST_VALUE(subq_25.user) OVER (
, FIRST_VALUE(subq_24.user) OVER (
PARTITION BY
subq_28.user
, subq_28.metric_time__day
, subq_28.mf_internal_uuid
ORDER BY subq_25.metric_time__day DESC
subq_27.user
, subq_27.metric_time__day
, subq_27.mf_internal_uuid
ORDER BY subq_24.metric_time__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
, subq_27.mf_internal_uuid AS mf_internal_uuid
, subq_27.buys AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'metric_time__day', 'user']
SELECT
metric_time__day
, subq_23.user
, subq_22.user
, visit__referrer_id
, visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
-- Read From CTE For node_id=sma_0
SELECT
DATETIME_TRUNC(ds, day) AS metric_time__day
, user_id AS user
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
) subq_23
metric_time__day
, sma_0_cte.user
, visit__referrer_id
, visits
FROM sma_0_cte sma_0_cte
) subq_22
WHERE visit__referrer_id = 'ref_id_01'
) subq_25
) subq_24
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
Expand All @@ -113,25 +123,25 @@ FROM (
, 1 AS buys
, GENERATE_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
) subq_28
) subq_27
ON
(
subq_25.user = subq_28.user
subq_24.user = subq_27.user
) AND (
(subq_25.metric_time__day <= subq_28.metric_time__day)
(subq_24.metric_time__day <= subq_27.metric_time__day)
)
) subq_29
) subq_28
GROUP BY
metric_time__day
, visit__referrer_id
) subq_32
) subq_31
ON
(
subq_21.visit__referrer_id = subq_32.visit__referrer_id
subq_21.visit__referrer_id = subq_31.visit__referrer_id
) AND (
subq_21.metric_time__day = subq_32.metric_time__day
subq_21.metric_time__day = subq_31.metric_time__day
)
GROUP BY
metric_time__day
, visit__referrer_id
) subq_33
) subq_32
Loading

0 comments on commit 3215b65

Please sign in to comment.