diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric__plan0.sql
index fb505c5256..e78459f108 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS FLOAT64) / CAST(NULLIF(subq_15.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS FLOAT64) / CAST(NULLIF(subq_16.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, GENERATE_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,23 +415,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
metric_time__day
- ) subq_14
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
metric_time__day
-) subq_15
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric__plan0_optimized.sql
index 14790809c8..dc5bb38f49 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATETIME_TRUNC(ds, day) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,19 +101,19 @@ FROM (
, 1 AS buys
, GENERATE_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
metric_time__day
-) subq_31
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_categorical_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_categorical_filter__plan0.sql
index 55ec032ba4..8271de7612 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_categorical_filter__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_categorical_filter__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , CAST(subq_15.buys AS FLOAT64) / CAST(NULLIF(subq_15.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , CAST(subq_16.buys AS FLOAT64) / CAST(NULLIF(subq_16.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id) AS visit__referrer_id
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -118,243 +118,289 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.visit__referrer_id
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.visit__referrer_id
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.visit__referrer_id
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.visit__referrer_id
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_8.visit__referrer_id) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visit__referrer_id
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visit__referrer_id
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, GENERATE_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -387,29 +433,29 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_14
+ ) subq_15
ON
(
- subq_4.visit__referrer_id = subq_14.visit__referrer_id
+ subq_4.visit__referrer_id = subq_15.visit__referrer_id
) AND (
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
)
GROUP BY
metric_time__day
, visit__referrer_id
-) subq_15
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_categorical_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
index acfdeb4045..74607a032f 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ 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
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -26,12 +26,12 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -43,60 +43,70 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_25.visit__referrer_id) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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 visit__referrer_id
- , FIRST_VALUE(subq_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATETIME_TRUNC(ds, day) AS ds__day
+ , 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
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -107,25 +117,25 @@ FROM (
, 1 AS buys
, GENERATE_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_30
+ ) subq_32
ON
(
- subq_20.visit__referrer_id = subq_30.visit__referrer_id
+ subq_21.visit__referrer_id = subq_32.visit__referrer_id
) AND (
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
)
GROUP BY
metric_time__day
, visit__referrer_id
-) subq_31
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0.sql
new file mode 100644
index 0000000000..f7d1ee2fb6
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0.sql
@@ -0,0 +1,438 @@
+-- Compute Metrics via Expressions
+SELECT
+ CAST(subq_18.buys AS FLOAT64) / CAST(NULLIF(subq_18.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ MAX(subq_5.visits) AS visits
+ , MAX(subq_17.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_4.visits) AS visits
+ FROM (
+ -- Pass Only Elements: ['visits',]
+ SELECT
+ subq_3.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.visits
+ FROM (
+ -- Pass Only Elements: ['visits', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_3
+ ) subq_4
+ ) subq_5
+ CROSS JOIN (
+ -- Pass Only Elements: ['buys',]
+ SELECT
+ subq_16.buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_15.metric_time__day
+ , SUM(subq_15.buys) AS buys
+ FROM (
+ -- Pass Only Elements: ['buys', 'metric_time__day']
+ SELECT
+ subq_14.metric_time__day
+ , subq_14.buys
+ FROM (
+ -- Find conversions for user within the range of INF
+ SELECT
+ subq_13.ds__day
+ , subq_13.metric_time__day
+ , subq_13.user
+ , subq_13.buys
+ , subq_13.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_9.visits) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_9.ds__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_9.user) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_12.mf_internal_uuid AS mf_internal_uuid
+ , subq_12.buys AS buys
+ FROM (
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ subq_8.ds__day
+ , subq_8.metric_time__day
+ , subq_8.user
+ , subq_8.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_8
+ ) subq_9
+ INNER JOIN (
+ -- Add column with generated UUID
+ SELECT
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.metric_time__day
+ , subq_11.metric_time__week
+ , subq_11.metric_time__month
+ , subq_11.metric_time__quarter
+ , subq_11.metric_time__year
+ , subq_11.metric_time__extract_year
+ , subq_11.metric_time__extract_quarter
+ , subq_11.metric_time__extract_month
+ , subq_11.metric_time__extract_day
+ , subq_11.metric_time__extract_dow
+ , subq_11.metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
+ , GENERATE_UUID() AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATETIME_TRUNC(buys_source_src_28000.ds, day) AS ds__day
+ , DATETIME_TRUNC(buys_source_src_28000.ds, isoweek) AS ds__week
+ , DATETIME_TRUNC(buys_source_src_28000.ds, month) AS ds__month
+ , DATETIME_TRUNC(buys_source_src_28000.ds, quarter) AS ds__quarter
+ , DATETIME_TRUNC(buys_source_src_28000.ds, year) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , IF(EXTRACT(dayofweek FROM buys_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM buys_source_src_28000.ds) - 1) AS ds__extract_dow
+ , EXTRACT(dayofyear FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATETIME_TRUNC(buys_source_src_28000.ds, day) AS buy__ds__day
+ , DATETIME_TRUNC(buys_source_src_28000.ds, isoweek) AS buy__ds__week
+ , DATETIME_TRUNC(buys_source_src_28000.ds, month) AS buy__ds__month
+ , DATETIME_TRUNC(buys_source_src_28000.ds, quarter) AS buy__ds__quarter
+ , DATETIME_TRUNC(buys_source_src_28000.ds, year) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , IF(EXTRACT(dayofweek FROM buys_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM buys_source_src_28000.ds) - 1) AS buy__ds__extract_dow
+ , EXTRACT(dayofyear FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ ON
+ (
+ subq_9.user = subq_12.user
+ ) AND (
+ (subq_9.ds__day <= subq_12.ds__day)
+ )
+ ) subq_13
+ ) subq_14
+ ) subq_15
+ GROUP BY
+ metric_time__day
+ ) subq_16
+ ) subq_17
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0_optimized.sql
new file mode 100644
index 0000000000..fe1074f92c
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0_optimized.sql
@@ -0,0 +1,106 @@
+-- Combine Aggregated Outputs
+-- Compute Metrics via Expressions
+SELECT
+ CAST(MAX(subq_35.buys) AS FLOAT64) / CAST(NULLIF(MAX(subq_24.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_21
+ WHERE metric_time__day = '2020-01-01'
+) subq_24
+CROSS JOIN (
+ -- Find conversions for user within the range of INF
+ -- 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_28.visits) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_28.ds__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_28.metric_time__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_28.user) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_31.mf_internal_uuid AS mf_internal_uuid
+ , subq_31.buys AS buys
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ ds__day
+ , metric_time__day
+ , subq_26.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_26
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_28
+ 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_31
+ ON
+ (
+ subq_28.user = subq_31.user
+ ) AND (
+ (subq_28.ds__day <= subq_31.ds__day)
+ )
+ ) subq_32
+ GROUP BY
+ metric_time__day
+) subq_35
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_time_constraint__plan0.sql
index eb3dbe8b63..df1b498c4f 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_time_constraint__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.visit__referrer_id
- , CAST(subq_17.buys AS FLOAT64) / CAST(NULLIF(subq_17.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate
+ subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS FLOAT64) / CAST(NULLIF(subq_18.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -158,277 +158,323 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id']
SELECT
- subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_13.ds__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, GENERATE_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -461,23 +507,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
- (subq_9.ds__day <= subq_12.ds__day)
+ (subq_10.ds__day <= subq_13.ds__day)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
visit__referrer_id
- ) subq_16
+ ) subq_17
ON
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
GROUP BY
visit__referrer_id
-) subq_17
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_time_constraint__plan0_optimized.sql
index 5c2bdafafd..26dd0198a7 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_time_constraint__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -24,11 +24,11 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATETIME_TRUNC(ds, day) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id']
@@ -39,53 +39,62 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- DATETIME_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_28000
- WHERE DATETIME_TRUNC(ds, day) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATETIME_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_28000
+ WHERE DATETIME_TRUNC(ds, day) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -96,19 +105,19 @@ FROM (
, 1 AS buys
, GENERATE_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
- (subq_27.ds__day <= subq_30.ds__day)
+ (subq_29.ds__day <= subq_32.ds__day)
)
- ) subq_31
+ ) subq_33
GROUP BY
visit__referrer_id
- ) subq_34
+ ) subq_36
ON
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
GROUP BY
visit__referrer_id
-) subq_35
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window__plan0.sql
index e624deff37..3a029448fe 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS FLOAT64) / CAST(NULLIF(subq_15.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate_7days
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS FLOAT64) / CAST(NULLIF(subq_16.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, GENERATE_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,27 +415,27 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
(
- subq_7.ds__day <= subq_10.ds__day
+ subq_8.ds__day <= subq_11.ds__day
) AND (
- subq_7.ds__day > DATE_SUB(CAST(subq_10.ds__day AS DATETIME), INTERVAL 7 day)
+ subq_8.ds__day > DATE_SUB(CAST(subq_11.ds__day AS DATETIME), INTERVAL 7 day)
)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
metric_time__day
- ) subq_14
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
metric_time__day
-) subq_15
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window__plan0_optimized.sql
index 7060991a4d..30e4dc3739 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATETIME_TRUNC(ds, day) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,23 +101,23 @@ FROM (
, 1 AS buys
, GENERATE_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
(
- subq_23.ds__day <= subq_26.ds__day
+ subq_25.ds__day <= subq_28.ds__day
) AND (
- subq_23.ds__day > DATE_SUB(CAST(subq_26.ds__day AS DATETIME), INTERVAL 7 day)
+ subq_25.ds__day > DATE_SUB(CAST(subq_28.ds__day AS DATETIME), INTERVAL 7 day)
)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
metric_time__day
-) subq_31
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window_and_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window_and_time_constraint__plan0.sql
index fb5c8699ff..ff2787aa41 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window_and_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window_and_time_constraint__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.metric_time__day
- , subq_17.visit__referrer_id
- , CAST(subq_17.buys AS FLOAT64) / CAST(NULLIF(subq_17.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate_7days
+ subq_18.metric_time__day
+ , subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS FLOAT64) / CAST(NULLIF(subq_18.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day) AS metric_time__day
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day) AS metric_time__day
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -164,289 +164,335 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_14.metric_time__day
- , subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.metric_time__day
+ , subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_13.ds__day
- , subq_13.metric_time__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.metric_time__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ , FIRST_VALUE(subq_10.metric_time__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.metric_time__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.metric_time__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, GENERATE_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -479,33 +525,33 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
(
- subq_9.ds__day <= subq_12.ds__day
+ subq_10.ds__day <= subq_13.ds__day
) AND (
- subq_9.ds__day > DATE_SUB(CAST(subq_12.ds__day AS DATETIME), INTERVAL 7 day)
+ subq_10.ds__day > DATE_SUB(CAST(subq_13.ds__day AS DATETIME), INTERVAL 7 day)
)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_16
+ ) subq_17
ON
(
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
) AND (
- subq_5.metric_time__day = subq_16.metric_time__day
+ subq_5.metric_time__day = subq_17.metric_time__day
)
GROUP BY
metric_time__day
, visit__referrer_id
-) subq_17
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
index d478aab86e..25a27b230b 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day) AS metric_time__day
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day) AS metric_time__day
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -28,12 +28,12 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATETIME_TRUNC(ds, day) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -45,62 +45,72 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.metric_time__day) OVER (
+ , FIRST_VALUE(subq_29.metric_time__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATETIME_TRUNC(ds, day) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , metric_time__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATETIME_TRUNC(ds, day) AS ds__day
+ , 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
+ WHERE DATETIME_TRUNC(ds, day) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -111,29 +121,29 @@ FROM (
, 1 AS buys
, GENERATE_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
(
- subq_27.ds__day <= subq_30.ds__day
+ subq_29.ds__day <= subq_32.ds__day
) AND (
- subq_27.ds__day > DATE_SUB(CAST(subq_30.ds__day AS DATETIME), INTERVAL 7 day)
+ subq_29.ds__day > DATE_SUB(CAST(subq_32.ds__day AS DATETIME), INTERVAL 7 day)
)
)
- ) subq_31
+ ) subq_33
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_34
+ ) subq_36
ON
(
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
) AND (
- subq_23.metric_time__day = subq_34.metric_time__day
+ subq_24.metric_time__day = subq_36.metric_time__day
)
GROUP BY
metric_time__day
, visit__referrer_id
-) subq_35
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric__plan0.sql
index 9e0429d976..502bd995ef 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,23 +415,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric__plan0_optimized.sql
index 2ca2302ef6..59b17b5176 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,19 +101,19 @@ FROM (
, 1 AS buys
, UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_categorical_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_categorical_filter__plan0.sql
index dc3f01d3a7..84354d3a94 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_categorical_filter__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_categorical_filter__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id) AS visit__referrer_id
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -118,243 +118,289 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.visit__referrer_id
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.visit__referrer_id
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.visit__referrer_id
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.visit__referrer_id
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_8.visit__referrer_id) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visit__referrer_id
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visit__referrer_id
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -387,29 +433,29 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- ) subq_14
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ ) subq_15
ON
(
- subq_4.visit__referrer_id = subq_14.visit__referrer_id
+ subq_4.visit__referrer_id = subq_15.visit__referrer_id
) AND (
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
)
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_categorical_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
index 2d192fb79d..c94d8ec89f 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ 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
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -26,12 +26,12 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -43,60 +43,70 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_25.visit__referrer_id) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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 visit__referrer_id
- , FIRST_VALUE(subq_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -107,25 +117,25 @@ FROM (
, 1 AS buys
, UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_30
+ ) subq_32
ON
(
- subq_20.visit__referrer_id = subq_30.visit__referrer_id
+ subq_21.visit__referrer_id = subq_32.visit__referrer_id
) AND (
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
)
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+ , COALESCE(subq_21.visit__referrer_id, subq_32.visit__referrer_id)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0.sql
new file mode 100644
index 0000000000..0d65081a67
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0.sql
@@ -0,0 +1,438 @@
+-- Compute Metrics via Expressions
+SELECT
+ CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ MAX(subq_5.visits) AS visits
+ , MAX(subq_17.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_4.visits) AS visits
+ FROM (
+ -- Pass Only Elements: ['visits',]
+ SELECT
+ subq_3.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.visits
+ FROM (
+ -- Pass Only Elements: ['visits', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_3
+ ) subq_4
+ ) subq_5
+ CROSS JOIN (
+ -- Pass Only Elements: ['buys',]
+ SELECT
+ subq_16.buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_15.metric_time__day
+ , SUM(subq_15.buys) AS buys
+ FROM (
+ -- Pass Only Elements: ['buys', 'metric_time__day']
+ SELECT
+ subq_14.metric_time__day
+ , subq_14.buys
+ FROM (
+ -- Find conversions for user within the range of INF
+ SELECT
+ subq_13.ds__day
+ , subq_13.metric_time__day
+ , subq_13.user
+ , subq_13.buys
+ , subq_13.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_9.visits) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_9.ds__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_9.user) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_12.mf_internal_uuid AS mf_internal_uuid
+ , subq_12.buys AS buys
+ FROM (
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ subq_8.ds__day
+ , subq_8.metric_time__day
+ , subq_8.user
+ , subq_8.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_8
+ ) subq_9
+ INNER JOIN (
+ -- Add column with generated UUID
+ SELECT
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.metric_time__day
+ , subq_11.metric_time__week
+ , subq_11.metric_time__month
+ , subq_11.metric_time__quarter
+ , subq_11.metric_time__year
+ , subq_11.metric_time__extract_year
+ , subq_11.metric_time__extract_quarter
+ , subq_11.metric_time__extract_month
+ , subq_11.metric_time__extract_day
+ , subq_11.metric_time__extract_dow
+ , subq_11.metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
+ , UUID() AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM buys_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ ON
+ (
+ subq_9.user = subq_12.user
+ ) AND (
+ (subq_9.ds__day <= subq_12.ds__day)
+ )
+ ) subq_13
+ ) subq_14
+ ) subq_15
+ GROUP BY
+ subq_15.metric_time__day
+ ) subq_16
+ ) subq_17
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0_optimized.sql
new file mode 100644
index 0000000000..85da26d6c5
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0_optimized.sql
@@ -0,0 +1,106 @@
+-- Combine Aggregated Outputs
+-- Compute Metrics via Expressions
+SELECT
+ CAST(MAX(subq_35.buys) AS DOUBLE) / CAST(NULLIF(MAX(subq_24.visits), 0) AS DOUBLE) 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
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_21
+ WHERE metric_time__day = '2020-01-01'
+) subq_24
+CROSS JOIN (
+ -- Find conversions for user within the range of INF
+ -- 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_28.visits) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_28.ds__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_28.metric_time__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_28.user) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_31.mf_internal_uuid AS mf_internal_uuid
+ , subq_31.buys AS buys
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ ds__day
+ , metric_time__day
+ , subq_26.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_26
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_28
+ 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_31
+ ON
+ (
+ subq_28.user = subq_31.user
+ ) AND (
+ (subq_28.ds__day <= subq_31.ds__day)
+ )
+ ) subq_32
+ GROUP BY
+ metric_time__day
+) subq_35
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_time_constraint__plan0.sql
index 2d5dbf536a..f49594dfd6 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_time_constraint__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -158,277 +158,323 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id']
SELECT
- subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_13.ds__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -461,23 +507,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
- (subq_9.ds__day <= subq_12.ds__day)
+ (subq_10.ds__day <= subq_13.ds__day)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.visit__referrer_id
- ) subq_16
+ subq_16.visit__referrer_id
+ ) subq_17
ON
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
GROUP BY
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_time_constraint__plan0_optimized.sql
index 0df77ffb03..f93f3d5c30 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_time_constraint__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -24,11 +24,11 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id']
@@ -39,53 +39,62 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , user_id AS user
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -96,19 +105,19 @@ FROM (
, 1 AS buys
, UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
- (subq_27.ds__day <= subq_30.ds__day)
+ (subq_29.ds__day <= subq_32.ds__day)
)
- ) subq_31
+ ) subq_33
GROUP BY
visit__referrer_id
- ) subq_34
+ ) subq_36
ON
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
GROUP BY
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window__plan0.sql
index 6948316384..dc477c42ce 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,27 +415,27 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
(
- subq_7.ds__day <= subq_10.ds__day
+ subq_8.ds__day <= subq_11.ds__day
) AND (
- subq_7.ds__day > DATEADD(day, -7, subq_10.ds__day)
+ subq_8.ds__day > DATEADD(day, -7, subq_11.ds__day)
)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window__plan0_optimized.sql
index 2a6d80d278..44656bd627 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,23 +101,23 @@ FROM (
, 1 AS buys
, UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
(
- subq_23.ds__day <= subq_26.ds__day
+ subq_25.ds__day <= subq_28.ds__day
) AND (
- subq_23.ds__day > DATEADD(day, -7, subq_26.ds__day)
+ subq_25.ds__day > DATEADD(day, -7, subq_28.ds__day)
)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window_and_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window_and_time_constraint__plan0.sql
index d411808964..9203cabbf1 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window_and_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window_and_time_constraint__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.metric_time__day
- , subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_18.metric_time__day
+ , subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day) AS metric_time__day
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day) AS metric_time__day
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -164,289 +164,335 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_14.metric_time__day
- , subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.metric_time__day
+ , subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_13.ds__day
- , subq_13.metric_time__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.metric_time__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ , FIRST_VALUE(subq_10.metric_time__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.metric_time__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.metric_time__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -479,33 +525,33 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
(
- subq_9.ds__day <= subq_12.ds__day
+ subq_10.ds__day <= subq_13.ds__day
) AND (
- subq_9.ds__day > DATEADD(day, -7, subq_12.ds__day)
+ subq_10.ds__day > DATEADD(day, -7, subq_13.ds__day)
)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- ) subq_16
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ ) subq_17
ON
(
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
) AND (
- subq_5.metric_time__day = subq_16.metric_time__day
+ subq_5.metric_time__day = subq_17.metric_time__day
)
GROUP BY
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day)
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day)
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
index c0a7cb56b3..f79d933d01 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day) AS metric_time__day
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day) AS metric_time__day
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -28,12 +28,12 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -45,62 +45,72 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.metric_time__day) OVER (
+ , FIRST_VALUE(subq_29.metric_time__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , metric_time__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) AS metric_time__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -111,29 +121,29 @@ FROM (
, 1 AS buys
, UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
(
- subq_27.ds__day <= subq_30.ds__day
+ subq_29.ds__day <= subq_32.ds__day
) AND (
- subq_27.ds__day > DATEADD(day, -7, subq_30.ds__day)
+ subq_29.ds__day > DATEADD(day, -7, subq_32.ds__day)
)
)
- ) subq_31
+ ) subq_33
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_34
+ ) subq_36
ON
(
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
) AND (
- subq_23.metric_time__day = subq_34.metric_time__day
+ subq_24.metric_time__day = subq_36.metric_time__day
)
GROUP BY
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day)
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day)
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0.sql
index 58ba934733..094ffea7ad 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,23 +415,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0_optimized.sql
index 8a91583adb..8928b1f4c0 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,19 +101,19 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0.sql
index fc3d6d87f5..4344ad97b6 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id) AS visit__referrer_id
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -118,243 +118,289 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.visit__referrer_id
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.visit__referrer_id
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.visit__referrer_id
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.visit__referrer_id
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_8.visit__referrer_id) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visit__referrer_id
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visit__referrer_id
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -387,29 +433,29 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- ) subq_14
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ ) subq_15
ON
(
- subq_4.visit__referrer_id = subq_14.visit__referrer_id
+ subq_4.visit__referrer_id = subq_15.visit__referrer_id
) AND (
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
)
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
index 6c179cce7f..f5428faea0 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ 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
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -26,12 +26,12 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -43,60 +43,70 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_25.visit__referrer_id) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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 visit__referrer_id
- , FIRST_VALUE(subq_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -107,25 +117,25 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_30
+ ) subq_32
ON
(
- subq_20.visit__referrer_id = subq_30.visit__referrer_id
+ subq_21.visit__referrer_id = subq_32.visit__referrer_id
) AND (
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
)
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+ , COALESCE(subq_21.visit__referrer_id, subq_32.visit__referrer_id)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0.sql
new file mode 100644
index 0000000000..619a169065
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0.sql
@@ -0,0 +1,438 @@
+-- Compute Metrics via Expressions
+SELECT
+ CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ MAX(subq_5.visits) AS visits
+ , MAX(subq_17.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_4.visits) AS visits
+ FROM (
+ -- Pass Only Elements: ['visits',]
+ SELECT
+ subq_3.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.visits
+ FROM (
+ -- Pass Only Elements: ['visits', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_3
+ ) subq_4
+ ) subq_5
+ CROSS JOIN (
+ -- Pass Only Elements: ['buys',]
+ SELECT
+ subq_16.buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_15.metric_time__day
+ , SUM(subq_15.buys) AS buys
+ FROM (
+ -- Pass Only Elements: ['buys', 'metric_time__day']
+ SELECT
+ subq_14.metric_time__day
+ , subq_14.buys
+ FROM (
+ -- Find conversions for user within the range of INF
+ SELECT
+ subq_13.ds__day
+ , subq_13.metric_time__day
+ , subq_13.user
+ , subq_13.buys
+ , subq_13.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_9.visits) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_9.ds__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_9.user) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_12.mf_internal_uuid AS mf_internal_uuid
+ , subq_12.buys AS buys
+ FROM (
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ subq_8.ds__day
+ , subq_8.metric_time__day
+ , subq_8.user
+ , subq_8.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_8
+ ) subq_9
+ INNER JOIN (
+ -- Add column with generated UUID
+ SELECT
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.metric_time__day
+ , subq_11.metric_time__week
+ , subq_11.metric_time__month
+ , subq_11.metric_time__quarter
+ , subq_11.metric_time__year
+ , subq_11.metric_time__extract_year
+ , subq_11.metric_time__extract_quarter
+ , subq_11.metric_time__extract_month
+ , subq_11.metric_time__extract_day
+ , subq_11.metric_time__extract_dow
+ , subq_11.metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
+ , GEN_RANDOM_UUID() AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ ON
+ (
+ subq_9.user = subq_12.user
+ ) AND (
+ (subq_9.ds__day <= subq_12.ds__day)
+ )
+ ) subq_13
+ ) subq_14
+ ) subq_15
+ GROUP BY
+ subq_15.metric_time__day
+ ) subq_16
+ ) subq_17
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0_optimized.sql
new file mode 100644
index 0000000000..5439cb33dd
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0_optimized.sql
@@ -0,0 +1,106 @@
+-- Combine Aggregated Outputs
+-- Compute Metrics via Expressions
+SELECT
+ CAST(MAX(subq_35.buys) AS DOUBLE) / CAST(NULLIF(MAX(subq_24.visits), 0) AS DOUBLE) 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
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_21
+ WHERE metric_time__day = '2020-01-01'
+) subq_24
+CROSS JOIN (
+ -- Find conversions for user within the range of INF
+ -- 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_28.visits) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_28.ds__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_28.metric_time__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_28.user) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_31.mf_internal_uuid AS mf_internal_uuid
+ , subq_31.buys AS buys
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ ds__day
+ , metric_time__day
+ , subq_26.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_26
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_28
+ 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
+ , GEN_RANDOM_UUID() AS mf_internal_uuid
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_31
+ ON
+ (
+ subq_28.user = subq_31.user
+ ) AND (
+ (subq_28.ds__day <= subq_31.ds__day)
+ )
+ ) subq_32
+ GROUP BY
+ metric_time__day
+) subq_35
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0.sql
index b1e85e150b..68fa7ef3fb 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -158,277 +158,323 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id']
SELECT
- subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_13.ds__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -461,23 +507,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
- (subq_9.ds__day <= subq_12.ds__day)
+ (subq_10.ds__day <= subq_13.ds__day)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.visit__referrer_id
- ) subq_16
+ subq_16.visit__referrer_id
+ ) subq_17
ON
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
GROUP BY
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0_optimized.sql
index 1269c6a617..91a10b183c 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -24,11 +24,11 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id']
@@ -39,53 +39,62 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , user_id AS user
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -96,19 +105,19 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
- (subq_27.ds__day <= subq_30.ds__day)
+ (subq_29.ds__day <= subq_32.ds__day)
)
- ) subq_31
+ ) subq_33
GROUP BY
visit__referrer_id
- ) subq_34
+ ) subq_36
ON
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
GROUP BY
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0.sql
index f4fe4a5c1a..a7b355b340 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,27 +415,27 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
(
- subq_7.ds__day <= subq_10.ds__day
+ subq_8.ds__day <= subq_11.ds__day
) AND (
- subq_7.ds__day > subq_10.ds__day - INTERVAL 7 day
+ subq_8.ds__day > subq_11.ds__day - INTERVAL 7 day
)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0_optimized.sql
index 82f1fe235c..9d34b0a1dc 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,23 +101,23 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
(
- subq_23.ds__day <= subq_26.ds__day
+ subq_25.ds__day <= subq_28.ds__day
) AND (
- subq_23.ds__day > subq_26.ds__day - INTERVAL 7 day
+ subq_25.ds__day > subq_28.ds__day - INTERVAL 7 day
)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0.sql
index d675fb6ad2..f4245bc4a3 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.metric_time__day
- , subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_18.metric_time__day
+ , subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day) AS metric_time__day
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day) AS metric_time__day
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -164,289 +164,335 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_14.metric_time__day
- , subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.metric_time__day
+ , subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_13.ds__day
- , subq_13.metric_time__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.metric_time__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ , FIRST_VALUE(subq_10.metric_time__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.metric_time__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.metric_time__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -479,33 +525,33 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
(
- subq_9.ds__day <= subq_12.ds__day
+ subq_10.ds__day <= subq_13.ds__day
) AND (
- subq_9.ds__day > subq_12.ds__day - INTERVAL 7 day
+ subq_10.ds__day > subq_13.ds__day - INTERVAL 7 day
)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- ) subq_16
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ ) subq_17
ON
(
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
) AND (
- subq_5.metric_time__day = subq_16.metric_time__day
+ subq_5.metric_time__day = subq_17.metric_time__day
)
GROUP BY
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day)
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day)
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
index 121a8a2629..84ef0b8132 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day) AS metric_time__day
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day) AS metric_time__day
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -28,12 +28,12 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -45,62 +45,72 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.metric_time__day) OVER (
+ , FIRST_VALUE(subq_29.metric_time__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , metric_time__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) AS metric_time__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -111,29 +121,29 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
(
- subq_27.ds__day <= subq_30.ds__day
+ subq_29.ds__day <= subq_32.ds__day
) AND (
- subq_27.ds__day > subq_30.ds__day - INTERVAL 7 day
+ subq_29.ds__day > subq_32.ds__day - INTERVAL 7 day
)
)
- ) subq_31
+ ) subq_33
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_34
+ ) subq_36
ON
(
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
) AND (
- subq_23.metric_time__day = subq_34.metric_time__day
+ subq_24.metric_time__day = subq_36.metric_time__day
)
GROUP BY
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day)
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day)
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric__plan0.sql
index 45bcc25f40..acc4a4eec0 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,23 +415,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric__plan0_optimized.sql
index f729a92ce9..b371ce692c 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,19 +101,19 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_categorical_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_categorical_filter__plan0.sql
index 7511fe9e6c..999db36ceb 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_categorical_filter__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_categorical_filter__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , CAST(subq_15.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , CAST(subq_16.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id) AS visit__referrer_id
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -118,243 +118,289 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.visit__referrer_id
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.visit__referrer_id
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.visit__referrer_id
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.visit__referrer_id
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_8.visit__referrer_id) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visit__referrer_id
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visit__referrer_id
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -387,29 +433,29 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- ) subq_14
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ ) subq_15
ON
(
- subq_4.visit__referrer_id = subq_14.visit__referrer_id
+ subq_4.visit__referrer_id = subq_15.visit__referrer_id
) AND (
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
)
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_categorical_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
index b06e52d6cf..492cbfbe44 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ 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
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -26,12 +26,12 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -43,60 +43,70 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_25.visit__referrer_id) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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 visit__referrer_id
- , FIRST_VALUE(subq_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -107,25 +117,25 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_30
+ ) subq_32
ON
(
- subq_20.visit__referrer_id = subq_30.visit__referrer_id
+ subq_21.visit__referrer_id = subq_32.visit__referrer_id
) AND (
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
)
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+ , COALESCE(subq_21.visit__referrer_id, subq_32.visit__referrer_id)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0.sql
new file mode 100644
index 0000000000..b7087e024b
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0.sql
@@ -0,0 +1,438 @@
+-- Compute Metrics via Expressions
+SELECT
+ CAST(subq_18.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ MAX(subq_5.visits) AS visits
+ , MAX(subq_17.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_4.visits) AS visits
+ FROM (
+ -- Pass Only Elements: ['visits',]
+ SELECT
+ subq_3.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.visits
+ FROM (
+ -- Pass Only Elements: ['visits', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_3
+ ) subq_4
+ ) subq_5
+ CROSS JOIN (
+ -- Pass Only Elements: ['buys',]
+ SELECT
+ subq_16.buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_15.metric_time__day
+ , SUM(subq_15.buys) AS buys
+ FROM (
+ -- Pass Only Elements: ['buys', 'metric_time__day']
+ SELECT
+ subq_14.metric_time__day
+ , subq_14.buys
+ FROM (
+ -- Find conversions for user within the range of INF
+ SELECT
+ subq_13.ds__day
+ , subq_13.metric_time__day
+ , subq_13.user
+ , subq_13.buys
+ , subq_13.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_9.visits) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_9.ds__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_9.user) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_12.mf_internal_uuid AS mf_internal_uuid
+ , subq_12.buys AS buys
+ FROM (
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ subq_8.ds__day
+ , subq_8.metric_time__day
+ , subq_8.user
+ , subq_8.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_8
+ ) subq_9
+ INNER JOIN (
+ -- Add column with generated UUID
+ SELECT
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.metric_time__day
+ , subq_11.metric_time__week
+ , subq_11.metric_time__month
+ , subq_11.metric_time__quarter
+ , subq_11.metric_time__year
+ , subq_11.metric_time__extract_year
+ , subq_11.metric_time__extract_quarter
+ , subq_11.metric_time__extract_month
+ , subq_11.metric_time__extract_day
+ , subq_11.metric_time__extract_dow
+ , subq_11.metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
+ , GEN_RANDOM_UUID() AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ ON
+ (
+ subq_9.user = subq_12.user
+ ) AND (
+ (subq_9.ds__day <= subq_12.ds__day)
+ )
+ ) subq_13
+ ) subq_14
+ ) subq_15
+ GROUP BY
+ subq_15.metric_time__day
+ ) subq_16
+ ) subq_17
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0_optimized.sql
new file mode 100644
index 0000000000..59158ba0cf
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0_optimized.sql
@@ -0,0 +1,106 @@
+-- Combine Aggregated Outputs
+-- Compute Metrics via Expressions
+SELECT
+ CAST(MAX(subq_35.buys) AS DOUBLE PRECISION) / CAST(NULLIF(MAX(subq_24.visits), 0) AS DOUBLE PRECISION) 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
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_21
+ WHERE metric_time__day = '2020-01-01'
+) subq_24
+CROSS JOIN (
+ -- Find conversions for user within the range of INF
+ -- 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_28.visits) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_28.ds__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_28.metric_time__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_28.user) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_31.mf_internal_uuid AS mf_internal_uuid
+ , subq_31.buys AS buys
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ ds__day
+ , metric_time__day
+ , subq_26.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_26
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_28
+ 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
+ , GEN_RANDOM_UUID() AS mf_internal_uuid
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_31
+ ON
+ (
+ subq_28.user = subq_31.user
+ ) AND (
+ (subq_28.ds__day <= subq_31.ds__day)
+ )
+ ) subq_32
+ GROUP BY
+ metric_time__day
+) subq_35
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_time_constraint__plan0.sql
index 089a2af327..2962a64f63 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_time_constraint__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
+ subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -158,277 +158,323 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id']
SELECT
- subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_13.ds__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -461,23 +507,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
- (subq_9.ds__day <= subq_12.ds__day)
+ (subq_10.ds__day <= subq_13.ds__day)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.visit__referrer_id
- ) subq_16
+ subq_16.visit__referrer_id
+ ) subq_17
ON
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
GROUP BY
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_time_constraint__plan0_optimized.sql
index 9a873c7c98..203faafa7a 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_time_constraint__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -24,11 +24,11 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id']
@@ -39,53 +39,62 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , user_id AS user
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -96,19 +105,19 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
- (subq_27.ds__day <= subq_30.ds__day)
+ (subq_29.ds__day <= subq_32.ds__day)
)
- ) subq_31
+ ) subq_33
GROUP BY
visit__referrer_id
- ) subq_34
+ ) subq_36
ON
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
GROUP BY
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window__plan0.sql
index f88c4a8812..a02d0ebc27 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,27 +415,27 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
(
- subq_7.ds__day <= subq_10.ds__day
+ subq_8.ds__day <= subq_11.ds__day
) AND (
- subq_7.ds__day > subq_10.ds__day - MAKE_INTERVAL(days => 7)
+ subq_8.ds__day > subq_11.ds__day - MAKE_INTERVAL(days => 7)
)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window__plan0_optimized.sql
index 94618c5f72..cf65b76be7 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,23 +101,23 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
(
- subq_23.ds__day <= subq_26.ds__day
+ subq_25.ds__day <= subq_28.ds__day
) AND (
- subq_23.ds__day > subq_26.ds__day - MAKE_INTERVAL(days => 7)
+ subq_25.ds__day > subq_28.ds__day - MAKE_INTERVAL(days => 7)
)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window_and_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window_and_time_constraint__plan0.sql
index 95f5b33f4c..e6d463aacd 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window_and_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window_and_time_constraint__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.metric_time__day
- , subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
+ subq_18.metric_time__day
+ , subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day) AS metric_time__day
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day) AS metric_time__day
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -164,289 +164,335 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_14.metric_time__day
- , subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.metric_time__day
+ , subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_13.ds__day
- , subq_13.metric_time__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.metric_time__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ , FIRST_VALUE(subq_10.metric_time__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.metric_time__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.metric_time__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -479,33 +525,33 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
(
- subq_9.ds__day <= subq_12.ds__day
+ subq_10.ds__day <= subq_13.ds__day
) AND (
- subq_9.ds__day > subq_12.ds__day - MAKE_INTERVAL(days => 7)
+ subq_10.ds__day > subq_13.ds__day - MAKE_INTERVAL(days => 7)
)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- ) subq_16
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ ) subq_17
ON
(
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
) AND (
- subq_5.metric_time__day = subq_16.metric_time__day
+ subq_5.metric_time__day = subq_17.metric_time__day
)
GROUP BY
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day)
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day)
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
index ab787834c1..1f151978c9 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day) AS metric_time__day
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day) AS metric_time__day
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -28,12 +28,12 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -45,62 +45,72 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.metric_time__day) OVER (
+ , FIRST_VALUE(subq_29.metric_time__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , metric_time__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) AS metric_time__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -111,29 +121,29 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
(
- subq_27.ds__day <= subq_30.ds__day
+ subq_29.ds__day <= subq_32.ds__day
) AND (
- subq_27.ds__day > subq_30.ds__day - MAKE_INTERVAL(days => 7)
+ subq_29.ds__day > subq_32.ds__day - MAKE_INTERVAL(days => 7)
)
)
- ) subq_31
+ ) subq_33
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_34
+ ) subq_36
ON
(
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
) AND (
- subq_23.metric_time__day = subq_34.metric_time__day
+ subq_24.metric_time__day = subq_36.metric_time__day
)
GROUP BY
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day)
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day)
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric__plan0.sql
index 2c457d1da7..06cfe21961 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,23 +415,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric__plan0_optimized.sql
index 06f8ca6cc6..b2d2c05860 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,19 +101,19 @@ FROM (
, 1 AS buys
, CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_categorical_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_categorical_filter__plan0.sql
index 6497c3264f..082aa9c264 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_categorical_filter__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_categorical_filter__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , CAST(subq_15.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , CAST(subq_16.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id) AS visit__referrer_id
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -118,243 +118,289 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.visit__referrer_id
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.visit__referrer_id
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.visit__referrer_id
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.visit__referrer_id
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_8.visit__referrer_id) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visit__referrer_id
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visit__referrer_id
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -387,29 +433,29 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- ) subq_14
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ ) subq_15
ON
(
- subq_4.visit__referrer_id = subq_14.visit__referrer_id
+ subq_4.visit__referrer_id = subq_15.visit__referrer_id
) AND (
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
)
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_categorical_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
index af0cf0df22..3757bbf5fe 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ 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
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -26,12 +26,12 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -43,60 +43,70 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_25.visit__referrer_id) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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 visit__referrer_id
- , FIRST_VALUE(subq_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -107,25 +117,25 @@ FROM (
, 1 AS buys
, CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_30
+ ) subq_32
ON
(
- subq_20.visit__referrer_id = subq_30.visit__referrer_id
+ subq_21.visit__referrer_id = subq_32.visit__referrer_id
) AND (
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
)
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+ , COALESCE(subq_21.visit__referrer_id, subq_32.visit__referrer_id)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0.sql
new file mode 100644
index 0000000000..b552bb725c
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0.sql
@@ -0,0 +1,438 @@
+-- Compute Metrics via Expressions
+SELECT
+ CAST(subq_18.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ MAX(subq_5.visits) AS visits
+ , MAX(subq_17.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_4.visits) AS visits
+ FROM (
+ -- Pass Only Elements: ['visits',]
+ SELECT
+ subq_3.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.visits
+ FROM (
+ -- Pass Only Elements: ['visits', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_3
+ ) subq_4
+ ) subq_5
+ CROSS JOIN (
+ -- Pass Only Elements: ['buys',]
+ SELECT
+ subq_16.buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_15.metric_time__day
+ , SUM(subq_15.buys) AS buys
+ FROM (
+ -- Pass Only Elements: ['buys', 'metric_time__day']
+ SELECT
+ subq_14.metric_time__day
+ , subq_14.buys
+ FROM (
+ -- Find conversions for user within the range of INF
+ SELECT
+ subq_13.ds__day
+ , subq_13.metric_time__day
+ , subq_13.user
+ , subq_13.buys
+ , subq_13.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_9.visits) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_9.ds__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_9.user) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_12.mf_internal_uuid AS mf_internal_uuid
+ , subq_12.buys AS buys
+ FROM (
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ subq_8.ds__day
+ , subq_8.metric_time__day
+ , subq_8.user
+ , subq_8.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_8
+ ) subq_9
+ INNER JOIN (
+ -- Add column with generated UUID
+ SELECT
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.metric_time__day
+ , subq_11.metric_time__week
+ , subq_11.metric_time__month
+ , subq_11.metric_time__quarter
+ , subq_11.metric_time__year
+ , subq_11.metric_time__extract_year
+ , subq_11.metric_time__extract_quarter
+ , subq_11.metric_time__extract_month
+ , subq_11.metric_time__extract_day
+ , subq_11.metric_time__extract_dow
+ , subq_11.metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
+ , CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM buys_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM buys_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM buys_source_src_28000.ds) END AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM buys_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM buys_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM buys_source_src_28000.ds) END AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ ON
+ (
+ subq_9.user = subq_12.user
+ ) AND (
+ (subq_9.ds__day <= subq_12.ds__day)
+ )
+ ) subq_13
+ ) subq_14
+ ) subq_15
+ GROUP BY
+ subq_15.metric_time__day
+ ) subq_16
+ ) subq_17
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0_optimized.sql
new file mode 100644
index 0000000000..db876c240b
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0_optimized.sql
@@ -0,0 +1,106 @@
+-- Combine Aggregated Outputs
+-- Compute Metrics via Expressions
+SELECT
+ CAST(MAX(subq_35.buys) AS DOUBLE PRECISION) / CAST(NULLIF(MAX(subq_24.visits), 0) AS DOUBLE PRECISION) 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
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_21
+ WHERE metric_time__day = '2020-01-01'
+) subq_24
+CROSS JOIN (
+ -- Find conversions for user within the range of INF
+ -- 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_28.visits) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_28.ds__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_28.metric_time__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_28.user) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_31.mf_internal_uuid AS mf_internal_uuid
+ , subq_31.buys AS buys
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ ds__day
+ , metric_time__day
+ , subq_26.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_26
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_28
+ 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
+ , CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_31
+ ON
+ (
+ subq_28.user = subq_31.user
+ ) AND (
+ (subq_28.ds__day <= subq_31.ds__day)
+ )
+ ) subq_32
+ GROUP BY
+ metric_time__day
+) subq_35
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_time_constraint__plan0.sql
index 469a9d5c46..97e24c78f0 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_time_constraint__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
+ subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -158,277 +158,323 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id']
SELECT
- subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_13.ds__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -461,23 +507,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
- (subq_9.ds__day <= subq_12.ds__day)
+ (subq_10.ds__day <= subq_13.ds__day)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.visit__referrer_id
- ) subq_16
+ subq_16.visit__referrer_id
+ ) subq_17
ON
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
GROUP BY
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_time_constraint__plan0_optimized.sql
index 1cf9773de6..5172ec57f9 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_time_constraint__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -24,11 +24,11 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id']
@@ -39,53 +39,62 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , user_id AS user
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -96,19 +105,19 @@ FROM (
, 1 AS buys
, CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
- (subq_27.ds__day <= subq_30.ds__day)
+ (subq_29.ds__day <= subq_32.ds__day)
)
- ) subq_31
+ ) subq_33
GROUP BY
visit__referrer_id
- ) subq_34
+ ) subq_36
ON
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
GROUP BY
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window__plan0.sql
index f5d8a8c3ff..904c97c297 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,27 +415,27 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
(
- subq_7.ds__day <= subq_10.ds__day
+ subq_8.ds__day <= subq_11.ds__day
) AND (
- subq_7.ds__day > DATEADD(day, -7, subq_10.ds__day)
+ subq_8.ds__day > DATEADD(day, -7, subq_11.ds__day)
)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window__plan0_optimized.sql
index 50f5012370..5177e11ea5 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,23 +101,23 @@ FROM (
, 1 AS buys
, CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
(
- subq_23.ds__day <= subq_26.ds__day
+ subq_25.ds__day <= subq_28.ds__day
) AND (
- subq_23.ds__day > DATEADD(day, -7, subq_26.ds__day)
+ subq_25.ds__day > DATEADD(day, -7, subq_28.ds__day)
)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window_and_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window_and_time_constraint__plan0.sql
index 8de5c90870..6b25f06f85 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window_and_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window_and_time_constraint__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.metric_time__day
- , subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
+ subq_18.metric_time__day
+ , subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day) AS metric_time__day
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day) AS metric_time__day
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -164,289 +164,335 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_14.metric_time__day
- , subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.metric_time__day
+ , subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_13.ds__day
- , subq_13.metric_time__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.metric_time__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ , FIRST_VALUE(subq_10.metric_time__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.metric_time__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.metric_time__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -479,33 +525,33 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
(
- subq_9.ds__day <= subq_12.ds__day
+ subq_10.ds__day <= subq_13.ds__day
) AND (
- subq_9.ds__day > DATEADD(day, -7, subq_12.ds__day)
+ subq_10.ds__day > DATEADD(day, -7, subq_13.ds__day)
)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- ) subq_16
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ ) subq_17
ON
(
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
) AND (
- subq_5.metric_time__day = subq_16.metric_time__day
+ subq_5.metric_time__day = subq_17.metric_time__day
)
GROUP BY
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day)
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day)
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
index 424adfe6b6..2929da476f 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day) AS metric_time__day
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day) AS metric_time__day
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -28,12 +28,12 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -45,62 +45,72 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.metric_time__day) OVER (
+ , FIRST_VALUE(subq_29.metric_time__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , metric_time__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) AS metric_time__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -111,29 +121,29 @@ FROM (
, 1 AS buys
, CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
(
- subq_27.ds__day <= subq_30.ds__day
+ subq_29.ds__day <= subq_32.ds__day
) AND (
- subq_27.ds__day > DATEADD(day, -7, subq_30.ds__day)
+ subq_29.ds__day > DATEADD(day, -7, subq_32.ds__day)
)
)
- ) subq_31
+ ) subq_33
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_34
+ ) subq_36
ON
(
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
) AND (
- subq_23.metric_time__day = subq_34.metric_time__day
+ subq_24.metric_time__day = subq_36.metric_time__day
)
GROUP BY
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day)
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day)
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric__plan0.sql
index 5523bdba87..52d82ca11e 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, UUID_STRING() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,23 +415,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric__plan0_optimized.sql
index 7e54f9421a..3cf5465df2 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,19 +101,19 @@ FROM (
, 1 AS buys
, UUID_STRING() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_categorical_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_categorical_filter__plan0.sql
index c834aff166..fce09bfdc3 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_categorical_filter__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_categorical_filter__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id) AS visit__referrer_id
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -118,243 +118,289 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.visit__referrer_id
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.visit__referrer_id
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.visit__referrer_id
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.visit__referrer_id
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_8.visit__referrer_id) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visit__referrer_id
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visit__referrer_id
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, UUID_STRING() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -387,29 +433,29 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- ) subq_14
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ ) subq_15
ON
(
- subq_4.visit__referrer_id = subq_14.visit__referrer_id
+ subq_4.visit__referrer_id = subq_15.visit__referrer_id
) AND (
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
)
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_categorical_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
index 9abb791996..32b8b8b67b 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ 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
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -26,12 +26,12 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -43,60 +43,70 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_25.visit__referrer_id) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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 visit__referrer_id
- , FIRST_VALUE(subq_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -107,25 +117,25 @@ FROM (
, 1 AS buys
, UUID_STRING() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_30
+ ) subq_32
ON
(
- subq_20.visit__referrer_id = subq_30.visit__referrer_id
+ subq_21.visit__referrer_id = subq_32.visit__referrer_id
) AND (
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
)
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+ , COALESCE(subq_21.visit__referrer_id, subq_32.visit__referrer_id)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0.sql
new file mode 100644
index 0000000000..0e38803c9f
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0.sql
@@ -0,0 +1,438 @@
+-- Compute Metrics via Expressions
+SELECT
+ CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ MAX(subq_5.visits) AS visits
+ , MAX(subq_17.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_4.visits) AS visits
+ FROM (
+ -- Pass Only Elements: ['visits',]
+ SELECT
+ subq_3.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.visits
+ FROM (
+ -- Pass Only Elements: ['visits', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_3
+ ) subq_4
+ ) subq_5
+ CROSS JOIN (
+ -- Pass Only Elements: ['buys',]
+ SELECT
+ subq_16.buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_15.metric_time__day
+ , SUM(subq_15.buys) AS buys
+ FROM (
+ -- Pass Only Elements: ['buys', 'metric_time__day']
+ SELECT
+ subq_14.metric_time__day
+ , subq_14.buys
+ FROM (
+ -- Find conversions for user within the range of INF
+ SELECT
+ subq_13.ds__day
+ , subq_13.metric_time__day
+ , subq_13.user
+ , subq_13.buys
+ , subq_13.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_9.visits) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_9.ds__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_9.user) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_12.mf_internal_uuid AS mf_internal_uuid
+ , subq_12.buys AS buys
+ FROM (
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ subq_8.ds__day
+ , subq_8.metric_time__day
+ , subq_8.user
+ , subq_8.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_8
+ ) subq_9
+ INNER JOIN (
+ -- Add column with generated UUID
+ SELECT
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.metric_time__day
+ , subq_11.metric_time__week
+ , subq_11.metric_time__month
+ , subq_11.metric_time__quarter
+ , subq_11.metric_time__year
+ , subq_11.metric_time__extract_year
+ , subq_11.metric_time__extract_quarter
+ , subq_11.metric_time__extract_month
+ , subq_11.metric_time__extract_day
+ , subq_11.metric_time__extract_dow
+ , subq_11.metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
+ , UUID_STRING() AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(dayofweekiso FROM buys_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , EXTRACT(dayofweekiso FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ ON
+ (
+ subq_9.user = subq_12.user
+ ) AND (
+ (subq_9.ds__day <= subq_12.ds__day)
+ )
+ ) subq_13
+ ) subq_14
+ ) subq_15
+ GROUP BY
+ subq_15.metric_time__day
+ ) subq_16
+ ) subq_17
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0_optimized.sql
new file mode 100644
index 0000000000..7936121475
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0_optimized.sql
@@ -0,0 +1,106 @@
+-- Combine Aggregated Outputs
+-- Compute Metrics via Expressions
+SELECT
+ CAST(MAX(subq_35.buys) AS DOUBLE) / CAST(NULLIF(MAX(subq_24.visits), 0) AS DOUBLE) 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
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_21
+ WHERE metric_time__day = '2020-01-01'
+) subq_24
+CROSS JOIN (
+ -- Find conversions for user within the range of INF
+ -- 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_28.visits) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_28.ds__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_28.metric_time__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_28.user) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_31.mf_internal_uuid AS mf_internal_uuid
+ , subq_31.buys AS buys
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ ds__day
+ , metric_time__day
+ , subq_26.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_26
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_28
+ 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_STRING() AS mf_internal_uuid
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_31
+ ON
+ (
+ subq_28.user = subq_31.user
+ ) AND (
+ (subq_28.ds__day <= subq_31.ds__day)
+ )
+ ) subq_32
+ GROUP BY
+ metric_time__day
+) subq_35
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_time_constraint__plan0.sql
index f7d795ed46..cce4aadfe9 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_time_constraint__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -158,277 +158,323 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id']
SELECT
- subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_13.ds__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, UUID_STRING() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -461,23 +507,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
- (subq_9.ds__day <= subq_12.ds__day)
+ (subq_10.ds__day <= subq_13.ds__day)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.visit__referrer_id
- ) subq_16
+ subq_16.visit__referrer_id
+ ) subq_17
ON
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
GROUP BY
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_time_constraint__plan0_optimized.sql
index 915716e167..6794fc19ba 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_time_constraint__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -24,11 +24,11 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id']
@@ -39,53 +39,62 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , user_id AS user
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -96,19 +105,19 @@ FROM (
, 1 AS buys
, UUID_STRING() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
- (subq_27.ds__day <= subq_30.ds__day)
+ (subq_29.ds__day <= subq_32.ds__day)
)
- ) subq_31
+ ) subq_33
GROUP BY
visit__referrer_id
- ) subq_34
+ ) subq_36
ON
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
GROUP BY
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window__plan0.sql
index 3187ba717e..03cdbeb870 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, UUID_STRING() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,27 +415,27 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
(
- subq_7.ds__day <= subq_10.ds__day
+ subq_8.ds__day <= subq_11.ds__day
) AND (
- subq_7.ds__day > DATEADD(day, -7, subq_10.ds__day)
+ subq_8.ds__day > DATEADD(day, -7, subq_11.ds__day)
)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window__plan0_optimized.sql
index 63b4b1290d..f73433d33c 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,23 +101,23 @@ FROM (
, 1 AS buys
, UUID_STRING() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
(
- subq_23.ds__day <= subq_26.ds__day
+ subq_25.ds__day <= subq_28.ds__day
) AND (
- subq_23.ds__day > DATEADD(day, -7, subq_26.ds__day)
+ subq_25.ds__day > DATEADD(day, -7, subq_28.ds__day)
)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window_and_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window_and_time_constraint__plan0.sql
index b6c8d12e0a..3bd7ccf595 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window_and_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window_and_time_constraint__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.metric_time__day
- , subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_18.metric_time__day
+ , subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day) AS metric_time__day
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day) AS metric_time__day
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -164,289 +164,335 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_14.metric_time__day
- , subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.metric_time__day
+ , subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_13.ds__day
- , subq_13.metric_time__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.metric_time__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ , FIRST_VALUE(subq_10.metric_time__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.metric_time__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.metric_time__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, UUID_STRING() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -479,33 +525,33 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
(
- subq_9.ds__day <= subq_12.ds__day
+ subq_10.ds__day <= subq_13.ds__day
) AND (
- subq_9.ds__day > DATEADD(day, -7, subq_12.ds__day)
+ subq_10.ds__day > DATEADD(day, -7, subq_13.ds__day)
)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- ) subq_16
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ ) subq_17
ON
(
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
) AND (
- subq_5.metric_time__day = subq_16.metric_time__day
+ subq_5.metric_time__day = subq_17.metric_time__day
)
GROUP BY
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day)
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day)
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
index 402c6443d7..aefaf3f621 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day) AS metric_time__day
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day) AS metric_time__day
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -28,12 +28,12 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -45,62 +45,72 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.metric_time__day) OVER (
+ , FIRST_VALUE(subq_29.metric_time__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
- ) subq_27
+ ds__day
+ , metric_time__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) AS metric_time__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -111,29 +121,29 @@ FROM (
, 1 AS buys
, UUID_STRING() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
(
- subq_27.ds__day <= subq_30.ds__day
+ subq_29.ds__day <= subq_32.ds__day
) AND (
- subq_27.ds__day > DATEADD(day, -7, subq_30.ds__day)
+ subq_29.ds__day > DATEADD(day, -7, subq_32.ds__day)
)
)
- ) subq_31
+ ) subq_33
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_34
+ ) subq_36
ON
(
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
) AND (
- subq_23.metric_time__day = subq_34.metric_time__day
+ subq_24.metric_time__day = subq_36.metric_time__day
)
GROUP BY
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day)
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day)
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric__plan0.sql
index b00bd24e15..561f039d14 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, uuid() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,23 +415,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric__plan0_optimized.sql
index 9fe6b6c32f..f2da3473a3 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,19 +101,19 @@ FROM (
, 1 AS buys
, uuid() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_categorical_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_categorical_filter__plan0.sql
index 32ba655478..25040c1169 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_categorical_filter__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_categorical_filter__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id) AS visit__referrer_id
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -118,243 +118,289 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.visit__referrer_id
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.visit__referrer_id
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.visit__referrer_id
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.visit__referrer_id
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_8.visit__referrer_id) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visit__referrer_id
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visit__referrer_id
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, uuid() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -387,29 +433,29 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
- (subq_7.ds__day <= subq_10.ds__day)
+ (subq_8.ds__day <= subq_11.ds__day)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- , subq_13.visit__referrer_id
- ) subq_14
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ ) subq_15
ON
(
- subq_4.visit__referrer_id = subq_14.visit__referrer_id
+ subq_4.visit__referrer_id = subq_15.visit__referrer_id
) AND (
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
)
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
- , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+ , COALESCE(subq_4.visit__referrer_id, subq_15.visit__referrer_id)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_categorical_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
index 4485f78bd4..7a956b7fbc 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_categorical_filter__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ 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
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -26,12 +26,12 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -43,60 +43,70 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_25.visit__referrer_id) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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 visit__referrer_id
- , FIRST_VALUE(subq_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -107,25 +117,25 @@ FROM (
, 1 AS buys
, uuid() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
- (subq_23.ds__day <= subq_26.ds__day)
+ (subq_25.ds__day <= subq_28.ds__day)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_30
+ ) subq_32
ON
(
- subq_20.visit__referrer_id = subq_30.visit__referrer_id
+ subq_21.visit__referrer_id = subq_32.visit__referrer_id
) AND (
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
)
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
- , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+ , COALESCE(subq_21.visit__referrer_id, subq_32.visit__referrer_id)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0.sql
new file mode 100644
index 0000000000..c697ee4518
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0.sql
@@ -0,0 +1,438 @@
+-- Compute Metrics via Expressions
+SELECT
+ CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ MAX(subq_5.visits) AS visits
+ , MAX(subq_17.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_4.visits) AS visits
+ FROM (
+ -- Pass Only Elements: ['visits',]
+ SELECT
+ subq_3.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.visits
+ FROM (
+ -- Pass Only Elements: ['visits', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_3
+ ) subq_4
+ ) subq_5
+ CROSS JOIN (
+ -- Pass Only Elements: ['buys',]
+ SELECT
+ subq_16.buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_15.metric_time__day
+ , SUM(subq_15.buys) AS buys
+ FROM (
+ -- Pass Only Elements: ['buys', 'metric_time__day']
+ SELECT
+ subq_14.metric_time__day
+ , subq_14.buys
+ FROM (
+ -- Find conversions for user within the range of INF
+ SELECT
+ subq_13.ds__day
+ , subq_13.metric_time__day
+ , subq_13.user
+ , subq_13.buys
+ , subq_13.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_9.visits) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_9.ds__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_9.user) OVER (
+ PARTITION BY
+ subq_12.user
+ , subq_12.ds__day
+ , subq_12.mf_internal_uuid
+ ORDER BY subq_9.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_12.mf_internal_uuid AS mf_internal_uuid
+ , subq_12.buys AS buys
+ FROM (
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ subq_8.ds__day
+ , subq_8.metric_time__day
+ , subq_8.user
+ , subq_8.visits
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_8
+ ) subq_9
+ INNER JOIN (
+ -- Add column with generated UUID
+ SELECT
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.metric_time__day
+ , subq_11.metric_time__week
+ , subq_11.metric_time__month
+ , subq_11.metric_time__quarter
+ , subq_11.metric_time__year
+ , subq_11.metric_time__extract_year
+ , subq_11.metric_time__extract_quarter
+ , subq_11.metric_time__extract_month
+ , subq_11.metric_time__extract_day
+ , subq_11.metric_time__extract_dow
+ , subq_11.metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
+ , uuid() AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ ON
+ (
+ subq_9.user = subq_12.user
+ ) AND (
+ (subq_9.ds__day <= subq_12.ds__day)
+ )
+ ) subq_13
+ ) subq_14
+ ) subq_15
+ GROUP BY
+ subq_15.metric_time__day
+ ) subq_16
+ ) subq_17
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0_optimized.sql
new file mode 100644
index 0000000000..d67d5af19c
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0_optimized.sql
@@ -0,0 +1,106 @@
+-- Combine Aggregated Outputs
+-- Compute Metrics via Expressions
+SELECT
+ CAST(MAX(subq_35.buys) AS DOUBLE) / CAST(NULLIF(MAX(subq_24.visits), 0) AS DOUBLE) 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
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_21
+ WHERE metric_time__day = '2020-01-01'
+) subq_24
+CROSS JOIN (
+ -- Find conversions for user within the range of INF
+ -- 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_28.visits) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_28.ds__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_28.metric_time__day) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_28.user) OVER (
+ PARTITION BY
+ subq_31.user
+ , subq_31.ds__day
+ , subq_31.mf_internal_uuid
+ ORDER BY subq_28.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_31.mf_internal_uuid AS mf_internal_uuid
+ , subq_31.buys AS buys
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ ds__day
+ , metric_time__day
+ , subq_26.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_26
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_28
+ 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_31
+ ON
+ (
+ subq_28.user = subq_31.user
+ ) AND (
+ (subq_28.ds__day <= subq_31.ds__day)
+ )
+ ) subq_32
+ GROUP BY
+ metric_time__day
+) subq_35
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_time_constraint__plan0.sql
index aad475508d..37e404e044 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_time_constraint__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+ subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -158,277 +158,323 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id']
SELECT
- subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of INF
SELECT
- subq_13.ds__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, uuid() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -461,23 +507,23 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
- (subq_9.ds__day <= subq_12.ds__day)
+ (subq_10.ds__day <= subq_13.ds__day)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.visit__referrer_id
- ) subq_16
+ subq_16.visit__referrer_id
+ ) subq_17
ON
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
GROUP BY
- COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_time_constraint__plan0_optimized.sql
index 156f22dc55..d77212989e 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_time_constraint__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -24,11 +24,11 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of INF
-- Pass Only Elements: ['buys', 'visit__referrer_id']
@@ -39,53 +39,62 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , user_id AS user
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
- ) subq_27
+ ds__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -96,19 +105,19 @@ FROM (
, 1 AS buys
, uuid() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
- (subq_27.ds__day <= subq_30.ds__day)
+ (subq_29.ds__day <= subq_32.ds__day)
)
- ) subq_31
+ ) subq_33
GROUP BY
visit__referrer_id
- ) subq_34
+ ) subq_36
ON
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
GROUP BY
- COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window__plan0.sql
index e11187b2a3..cc7a53c7c4 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window__plan0.sql
@@ -1,13 +1,13 @@
-- Compute Metrics via Expressions
SELECT
- subq_15.metric_time__day
- , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_16.metric_time__day
+ , CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day) AS metric_time__day
, MAX(subq_4.visits) AS visits
- , MAX(subq_14.buys) AS buys
+ , MAX(subq_15.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -112,231 +112,277 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_13.metric_time__day
- , SUM(subq_13.buys) AS buys
+ subq_14.metric_time__day
+ , SUM(subq_14.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'metric_time__day']
SELECT
- subq_12.metric_time__day
- , subq_12.buys
+ subq_13.metric_time__day
+ , subq_13.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_11.ds__day
- , subq_11.metric_time__day
- , subq_11.user
- , subq_11.buys
- , subq_11.visits
+ subq_12.ds__day
+ , subq_12.metric_time__day
+ , subq_12.user
+ , subq_12.buys
+ , subq_12.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_7.visits) OVER (
+ FIRST_VALUE(subq_8.visits) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_7.ds__day) OVER (
+ , FIRST_VALUE(subq_8.ds__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_7.metric_time__day) OVER (
+ , FIRST_VALUE(subq_8.metric_time__day) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_7.user) OVER (
+ , FIRST_VALUE(subq_8.user) OVER (
PARTITION BY
- subq_10.user
- , subq_10.ds__day
- , subq_10.mf_internal_uuid
- ORDER BY subq_7.ds__day DESC
+ subq_11.user
+ , subq_11.ds__day
+ , subq_11.mf_internal_uuid
+ ORDER BY subq_8.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_10.mf_internal_uuid AS mf_internal_uuid
- , subq_10.buys AS buys
+ , subq_11.mf_internal_uuid AS mf_internal_uuid
+ , subq_11.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_6.ds__day
- , subq_6.metric_time__day
- , subq_6.user
- , subq_6.visits
+ subq_7.ds__day
+ , subq_7.metric_time__day
+ , subq_7.user
+ , subq_7.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.visit__ds__day
- , subq_5.visit__ds__week
- , subq_5.visit__ds__month
- , subq_5.visit__ds__quarter
- , subq_5.visit__ds__year
- , subq_5.visit__ds__extract_year
- , subq_5.visit__ds__extract_quarter
- , subq_5.visit__ds__extract_month
- , subq_5.visit__ds__extract_day
- , subq_5.visit__ds__extract_dow
- , subq_5.visit__ds__extract_doy
- , subq_5.ds__day AS metric_time__day
- , subq_5.ds__week AS metric_time__week
- , subq_5.ds__month AS metric_time__month
- , subq_5.ds__quarter AS metric_time__quarter
- , subq_5.ds__year AS metric_time__year
- , subq_5.ds__extract_year AS metric_time__extract_year
- , subq_5.ds__extract_quarter AS metric_time__extract_quarter
- , subq_5.ds__extract_month AS metric_time__extract_month
- , subq_5.ds__extract_day AS metric_time__extract_day
- , subq_5.ds__extract_dow AS metric_time__extract_dow
- , subq_5.ds__extract_doy AS metric_time__extract_doy
- , subq_5.user
- , subq_5.session
- , subq_5.visit__user
- , subq_5.visit__session
- , subq_5.referrer_id
- , subq_5.visit__referrer_id
- , subq_5.visits
- , subq_5.visitors
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.metric_time__day
+ , subq_6.metric_time__week
+ , subq_6.metric_time__month
+ , subq_6.metric_time__quarter
+ , subq_6.metric_time__year
+ , subq_6.metric_time__extract_year
+ , subq_6.metric_time__extract_quarter
+ , subq_6.metric_time__extract_month
+ , subq_6.metric_time__extract_day
+ , subq_6.metric_time__extract_dow
+ , subq_6.metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_5
- ) subq_6
- ) subq_7
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.visit__ds__day
+ , subq_5.visit__ds__week
+ , subq_5.visit__ds__month
+ , subq_5.visit__ds__quarter
+ , subq_5.visit__ds__year
+ , subq_5.visit__ds__extract_year
+ , subq_5.visit__ds__extract_quarter
+ , subq_5.visit__ds__extract_month
+ , subq_5.visit__ds__extract_day
+ , subq_5.visit__ds__extract_dow
+ , subq_5.visit__ds__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__user
+ , subq_5.visit__session
+ , subq_5.referrer_id
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ , subq_5.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_5
+ ) subq_6
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_7
+ ) subq_8
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_9.ds__day
- , subq_9.ds__week
- , subq_9.ds__month
- , subq_9.ds__quarter
- , subq_9.ds__year
- , subq_9.ds__extract_year
- , subq_9.ds__extract_quarter
- , subq_9.ds__extract_month
- , subq_9.ds__extract_day
- , subq_9.ds__extract_dow
- , subq_9.ds__extract_doy
- , subq_9.buy__ds__day
- , subq_9.buy__ds__week
- , subq_9.buy__ds__month
- , subq_9.buy__ds__quarter
- , subq_9.buy__ds__year
- , subq_9.buy__ds__extract_year
- , subq_9.buy__ds__extract_quarter
- , subq_9.buy__ds__extract_month
- , subq_9.buy__ds__extract_day
- , subq_9.buy__ds__extract_dow
- , subq_9.buy__ds__extract_doy
- , subq_9.metric_time__day
- , subq_9.metric_time__week
- , subq_9.metric_time__month
- , subq_9.metric_time__quarter
- , subq_9.metric_time__year
- , subq_9.metric_time__extract_year
- , subq_9.metric_time__extract_quarter
- , subq_9.metric_time__extract_month
- , subq_9.metric_time__extract_day
- , subq_9.metric_time__extract_dow
- , subq_9.metric_time__extract_doy
- , subq_9.user
- , subq_9.session_id
- , subq_9.buy__user
- , subq_9.buy__session_id
- , subq_9.buys
- , subq_9.buyers
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.buy__ds__day
+ , subq_10.buy__ds__week
+ , subq_10.buy__ds__month
+ , subq_10.buy__ds__quarter
+ , subq_10.buy__ds__year
+ , subq_10.buy__ds__extract_year
+ , subq_10.buy__ds__extract_quarter
+ , subq_10.buy__ds__extract_month
+ , subq_10.buy__ds__extract_day
+ , subq_10.buy__ds__extract_dow
+ , subq_10.buy__ds__extract_doy
+ , subq_10.metric_time__day
+ , subq_10.metric_time__week
+ , subq_10.metric_time__month
+ , subq_10.metric_time__quarter
+ , subq_10.metric_time__year
+ , subq_10.metric_time__extract_year
+ , subq_10.metric_time__extract_quarter
+ , subq_10.metric_time__extract_month
+ , subq_10.metric_time__extract_day
+ , subq_10.metric_time__extract_dow
+ , subq_10.metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session_id
+ , subq_10.buy__user
+ , subq_10.buy__session_id
+ , subq_10.buys
+ , subq_10.buyers
, uuid() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_8.ds__day
- , subq_8.ds__week
- , subq_8.ds__month
- , subq_8.ds__quarter
- , subq_8.ds__year
- , subq_8.ds__extract_year
- , subq_8.ds__extract_quarter
- , subq_8.ds__extract_month
- , subq_8.ds__extract_day
- , subq_8.ds__extract_dow
- , subq_8.ds__extract_doy
- , subq_8.buy__ds__day
- , subq_8.buy__ds__week
- , subq_8.buy__ds__month
- , subq_8.buy__ds__quarter
- , subq_8.buy__ds__year
- , subq_8.buy__ds__extract_year
- , subq_8.buy__ds__extract_quarter
- , subq_8.buy__ds__extract_month
- , subq_8.buy__ds__extract_day
- , subq_8.buy__ds__extract_dow
- , subq_8.buy__ds__extract_doy
- , subq_8.ds__day AS metric_time__day
- , subq_8.ds__week AS metric_time__week
- , subq_8.ds__month AS metric_time__month
- , subq_8.ds__quarter AS metric_time__quarter
- , subq_8.ds__year AS metric_time__year
- , subq_8.ds__extract_year AS metric_time__extract_year
- , subq_8.ds__extract_quarter AS metric_time__extract_quarter
- , subq_8.ds__extract_month AS metric_time__extract_month
- , subq_8.ds__extract_day AS metric_time__extract_day
- , subq_8.ds__extract_dow AS metric_time__extract_dow
- , subq_8.ds__extract_doy AS metric_time__extract_doy
- , subq_8.user
- , subq_8.session_id
- , subq_8.buy__user
- , subq_8.buy__session_id
- , subq_8.buys
- , subq_8.buyers
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.buy__ds__day
+ , subq_9.buy__ds__week
+ , subq_9.buy__ds__month
+ , subq_9.buy__ds__quarter
+ , subq_9.buy__ds__year
+ , subq_9.buy__ds__extract_year
+ , subq_9.buy__ds__extract_quarter
+ , subq_9.buy__ds__extract_month
+ , subq_9.buy__ds__extract_day
+ , subq_9.buy__ds__extract_dow
+ , subq_9.buy__ds__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.user
+ , subq_9.session_id
+ , subq_9.buy__user
+ , subq_9.buy__session_id
+ , subq_9.buys
+ , subq_9.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -369,27 +415,27 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_8
- ) subq_9
- ) subq_10
+ ) subq_9
+ ) subq_10
+ ) subq_11
ON
(
- subq_7.user = subq_10.user
+ subq_8.user = subq_11.user
) AND (
(
- subq_7.ds__day <= subq_10.ds__day
+ subq_8.ds__day <= subq_11.ds__day
) AND (
- subq_7.ds__day > DATE_ADD('day', -7, subq_10.ds__day)
+ subq_8.ds__day > DATE_ADD('day', -7, subq_11.ds__day)
)
)
- ) subq_11
- ) subq_12
- ) subq_13
+ ) subq_12
+ ) subq_13
+ ) subq_14
GROUP BY
- subq_13.metric_time__day
- ) subq_14
+ subq_14.metric_time__day
+ ) subq_15
ON
- subq_4.metric_time__day = subq_14.metric_time__day
+ subq_4.metric_time__day = subq_15.metric_time__day
GROUP BY
- COALESCE(subq_4.metric_time__day, subq_14.metric_time__day)
-) subq_15
+ COALESCE(subq_4.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window__plan0_optimized.sql
index 818bd3b5df..220f7f6ffb 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window__plan0_optimized.sql
@@ -5,9 +5,9 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day
- , MAX(subq_20.visits) AS visits
- , MAX(subq_30.buys) AS buys
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_21.visits) AS visits
+ , MAX(subq_32.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -22,11 +22,11 @@ FROM (
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_18
+ ) subq_19
WHERE metric_time__day = '2020-01-01'
GROUP BY
metric_time__day
- ) subq_20
+ ) subq_21
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'metric_time__day']
@@ -37,51 +37,60 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_23.visits) OVER (
+ FIRST_VALUE(subq_25.visits) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.ds__day) OVER (
+ , FIRST_VALUE(subq_25.ds__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.metric_time__day) OVER (
+ , FIRST_VALUE(subq_25.metric_time__day) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_23.user) OVER (
+ , FIRST_VALUE(subq_25.user) OVER (
PARTITION BY
- subq_26.user
- , subq_26.ds__day
- , subq_26.mf_internal_uuid
- ORDER BY subq_23.ds__day DESC
+ 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_26.mf_internal_uuid AS mf_internal_uuid
- , subq_26.buys AS buys
+ , 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'
+ -- Constrain Output with WHERE
-- 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_23
+ ds__day
+ , metric_time__day
+ , subq_23.user
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ 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_23
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_25
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -92,23 +101,23 @@ FROM (
, 1 AS buys
, uuid() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_26
+ ) subq_28
ON
(
- subq_23.user = subq_26.user
+ subq_25.user = subq_28.user
) AND (
(
- subq_23.ds__day <= subq_26.ds__day
+ subq_25.ds__day <= subq_28.ds__day
) AND (
- subq_23.ds__day > DATE_ADD('day', -7, subq_26.ds__day)
+ subq_25.ds__day > DATE_ADD('day', -7, subq_28.ds__day)
)
)
- ) subq_27
+ ) subq_29
GROUP BY
metric_time__day
- ) subq_30
+ ) subq_32
ON
- subq_20.metric_time__day = subq_30.metric_time__day
+ subq_21.metric_time__day = subq_32.metric_time__day
GROUP BY
- COALESCE(subq_20.metric_time__day, subq_30.metric_time__day)
-) subq_31
+ COALESCE(subq_21.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window_and_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window_and_time_constraint__plan0.sql
index fd4d76d852..61bc9c931f 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window_and_time_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window_and_time_constraint__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_17.metric_time__day
- , subq_17.visit__referrer_id
- , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_18.metric_time__day
+ , subq_18.visit__referrer_id
+ , CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day) AS metric_time__day
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day) AS metric_time__day
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id) AS visit__referrer_id
, MAX(subq_5.visits) AS visits
- , MAX(subq_16.buys) AS buys
+ , MAX(subq_17.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -164,289 +164,335 @@ FROM (
FULL OUTER JOIN (
-- Aggregate Measures
SELECT
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- , SUM(subq_15.buys) AS buys
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ , SUM(subq_16.buys) AS buys
FROM (
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_14.metric_time__day
- , subq_14.visit__referrer_id
- , subq_14.buys
+ subq_15.metric_time__day
+ , subq_15.visit__referrer_id
+ , subq_15.buys
FROM (
-- Find conversions for user within the range of 7 day
SELECT
- subq_13.ds__day
- , subq_13.metric_time__day
- , subq_13.user
- , subq_13.visit__referrer_id
- , subq_13.buys
- , subq_13.visits
+ subq_14.ds__day
+ , subq_14.metric_time__day
+ , subq_14.user
+ , subq_14.visit__referrer_id
+ , subq_14.buys
+ , subq_14.visits
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_9.visits) OVER (
+ FIRST_VALUE(subq_10.visits) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_9.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_10.visit__referrer_id) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_9.ds__day) OVER (
+ , FIRST_VALUE(subq_10.ds__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_9.metric_time__day) OVER (
+ , FIRST_VALUE(subq_10.metric_time__day) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_9.user) OVER (
+ , FIRST_VALUE(subq_10.user) OVER (
PARTITION BY
- subq_12.user
- , subq_12.ds__day
- , subq_12.mf_internal_uuid
- ORDER BY subq_9.ds__day DESC
+ subq_13.user
+ , subq_13.ds__day
+ , subq_13.mf_internal_uuid
+ ORDER BY subq_10.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_12.mf_internal_uuid AS mf_internal_uuid
- , subq_12.buys AS buys
+ , subq_13.mf_internal_uuid AS mf_internal_uuid
+ , subq_13.buys AS buys
FROM (
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_8.ds__day
- , subq_8.metric_time__day
- , subq_8.user
- , subq_8.visit__referrer_id
- , subq_8.visits
+ subq_9.ds__day
+ , subq_9.metric_time__day
+ , subq_9.user
+ , subq_9.visit__referrer_id
+ , subq_9.visits
FROM (
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
SELECT
- subq_7.ds__day
- , subq_7.ds__week
- , subq_7.ds__month
- , subq_7.ds__quarter
- , subq_7.ds__year
- , subq_7.ds__extract_year
- , subq_7.ds__extract_quarter
- , subq_7.ds__extract_month
- , subq_7.ds__extract_day
- , subq_7.ds__extract_dow
- , subq_7.ds__extract_doy
- , subq_7.visit__ds__day
- , subq_7.visit__ds__week
- , subq_7.visit__ds__month
- , subq_7.visit__ds__quarter
- , subq_7.visit__ds__year
- , subq_7.visit__ds__extract_year
- , subq_7.visit__ds__extract_quarter
- , subq_7.visit__ds__extract_month
- , subq_7.visit__ds__extract_day
- , subq_7.visit__ds__extract_dow
- , subq_7.visit__ds__extract_doy
- , subq_7.metric_time__day
- , subq_7.metric_time__week
- , subq_7.metric_time__month
- , subq_7.metric_time__quarter
- , subq_7.metric_time__year
- , subq_7.metric_time__extract_year
- , subq_7.metric_time__extract_quarter
- , subq_7.metric_time__extract_month
- , subq_7.metric_time__extract_day
- , subq_7.metric_time__extract_dow
- , subq_7.metric_time__extract_doy
- , subq_7.user
- , subq_7.session
- , subq_7.visit__user
- , subq_7.visit__session
- , subq_7.referrer_id
- , subq_7.visit__referrer_id
- , subq_7.visits
- , subq_7.visitors
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.visit__ds__day
+ , subq_8.visit__ds__week
+ , subq_8.visit__ds__month
+ , subq_8.visit__ds__quarter
+ , subq_8.visit__ds__year
+ , subq_8.visit__ds__extract_year
+ , subq_8.visit__ds__extract_quarter
+ , subq_8.visit__ds__extract_month
+ , subq_8.visit__ds__extract_day
+ , subq_8.visit__ds__extract_dow
+ , subq_8.visit__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session
+ , subq_8.visit__user
+ , subq_8.visit__session
+ , subq_8.referrer_id
+ , subq_8.visit__referrer_id
+ , subq_8.visits
+ , subq_8.visitors
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
SELECT
- subq_6.ds__day
- , subq_6.ds__week
- , subq_6.ds__month
- , subq_6.ds__quarter
- , subq_6.ds__year
- , subq_6.ds__extract_year
- , subq_6.ds__extract_quarter
- , subq_6.ds__extract_month
- , subq_6.ds__extract_day
- , subq_6.ds__extract_dow
- , subq_6.ds__extract_doy
- , subq_6.visit__ds__day
- , subq_6.visit__ds__week
- , subq_6.visit__ds__month
- , subq_6.visit__ds__quarter
- , subq_6.visit__ds__year
- , subq_6.visit__ds__extract_year
- , subq_6.visit__ds__extract_quarter
- , subq_6.visit__ds__extract_month
- , subq_6.visit__ds__extract_day
- , subq_6.visit__ds__extract_dow
- , subq_6.visit__ds__extract_doy
- , subq_6.ds__day AS metric_time__day
- , subq_6.ds__week AS metric_time__week
- , subq_6.ds__month AS metric_time__month
- , subq_6.ds__quarter AS metric_time__quarter
- , subq_6.ds__year AS metric_time__year
- , subq_6.ds__extract_year AS metric_time__extract_year
- , subq_6.ds__extract_quarter AS metric_time__extract_quarter
- , subq_6.ds__extract_month AS metric_time__extract_month
- , subq_6.ds__extract_day AS metric_time__extract_day
- , subq_6.ds__extract_dow AS metric_time__extract_dow
- , subq_6.ds__extract_doy AS metric_time__extract_doy
- , subq_6.user
- , subq_6.session
- , subq_6.visit__user
- , subq_6.visit__session
- , subq_6.referrer_id
- , subq_6.visit__referrer_id
- , subq_6.visits
- , subq_6.visitors
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.visit__ds__day
+ , subq_7.visit__ds__week
+ , subq_7.visit__ds__month
+ , subq_7.visit__ds__quarter
+ , subq_7.visit__ds__year
+ , subq_7.visit__ds__extract_year
+ , subq_7.visit__ds__extract_quarter
+ , subq_7.visit__ds__extract_month
+ , subq_7.visit__ds__extract_day
+ , subq_7.visit__ds__extract_dow
+ , subq_7.visit__ds__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session
+ , subq_7.visit__user
+ , subq_7.visit__session
+ , subq_7.referrer_id
+ , subq_7.visit__referrer_id
+ , subq_7.visits
+ , subq_7.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_6
- ) subq_7
- WHERE subq_7.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
- ) subq_8
- ) subq_9
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.visit__ds__day
+ , subq_6.visit__ds__week
+ , subq_6.visit__ds__month
+ , subq_6.visit__ds__quarter
+ , subq_6.visit__ds__year
+ , subq_6.visit__ds__extract_year
+ , subq_6.visit__ds__extract_quarter
+ , subq_6.visit__ds__extract_month
+ , subq_6.visit__ds__extract_day
+ , subq_6.visit__ds__extract_dow
+ , subq_6.visit__ds__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.user
+ , subq_6.session
+ , subq_6.visit__user
+ , subq_6.visit__session
+ , subq_6.referrer_id
+ , subq_6.visit__referrer_id
+ , subq_6.visits
+ , subq_6.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
+ ) subq_8
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_9
+ ) subq_10
INNER JOIN (
-- Add column with generated UUID
SELECT
- subq_11.ds__day
- , subq_11.ds__week
- , subq_11.ds__month
- , subq_11.ds__quarter
- , subq_11.ds__year
- , subq_11.ds__extract_year
- , subq_11.ds__extract_quarter
- , subq_11.ds__extract_month
- , subq_11.ds__extract_day
- , subq_11.ds__extract_dow
- , subq_11.ds__extract_doy
- , subq_11.buy__ds__day
- , subq_11.buy__ds__week
- , subq_11.buy__ds__month
- , subq_11.buy__ds__quarter
- , subq_11.buy__ds__year
- , subq_11.buy__ds__extract_year
- , subq_11.buy__ds__extract_quarter
- , subq_11.buy__ds__extract_month
- , subq_11.buy__ds__extract_day
- , subq_11.buy__ds__extract_dow
- , subq_11.buy__ds__extract_doy
- , subq_11.metric_time__day
- , subq_11.metric_time__week
- , subq_11.metric_time__month
- , subq_11.metric_time__quarter
- , subq_11.metric_time__year
- , subq_11.metric_time__extract_year
- , subq_11.metric_time__extract_quarter
- , subq_11.metric_time__extract_month
- , subq_11.metric_time__extract_day
- , subq_11.metric_time__extract_dow
- , subq_11.metric_time__extract_doy
- , subq_11.user
- , subq_11.session_id
- , subq_11.buy__user
- , subq_11.buy__session_id
- , subq_11.buys
- , subq_11.buyers
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.buy__ds__day
+ , subq_12.buy__ds__week
+ , subq_12.buy__ds__month
+ , subq_12.buy__ds__quarter
+ , subq_12.buy__ds__year
+ , subq_12.buy__ds__extract_year
+ , subq_12.buy__ds__extract_quarter
+ , subq_12.buy__ds__extract_month
+ , subq_12.buy__ds__extract_day
+ , subq_12.buy__ds__extract_dow
+ , subq_12.buy__ds__extract_doy
+ , subq_12.metric_time__day
+ , subq_12.metric_time__week
+ , subq_12.metric_time__month
+ , subq_12.metric_time__quarter
+ , subq_12.metric_time__year
+ , subq_12.metric_time__extract_year
+ , subq_12.metric_time__extract_quarter
+ , subq_12.metric_time__extract_month
+ , subq_12.metric_time__extract_day
+ , subq_12.metric_time__extract_dow
+ , subq_12.metric_time__extract_doy
+ , subq_12.user
+ , subq_12.session_id
+ , subq_12.buy__user
+ , subq_12.buy__session_id
+ , subq_12.buys
+ , subq_12.buyers
, uuid() AS mf_internal_uuid
FROM (
-- Metric Time Dimension 'ds'
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.buy__ds__day
- , subq_10.buy__ds__week
- , subq_10.buy__ds__month
- , subq_10.buy__ds__quarter
- , subq_10.buy__ds__year
- , subq_10.buy__ds__extract_year
- , subq_10.buy__ds__extract_quarter
- , subq_10.buy__ds__extract_month
- , subq_10.buy__ds__extract_day
- , subq_10.buy__ds__extract_dow
- , subq_10.buy__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session_id
- , subq_10.buy__user
- , subq_10.buy__session_id
- , subq_10.buys
- , subq_10.buyers
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.buy__ds__day
+ , subq_11.buy__ds__week
+ , subq_11.buy__ds__month
+ , subq_11.buy__ds__quarter
+ , subq_11.buy__ds__year
+ , subq_11.buy__ds__extract_year
+ , subq_11.buy__ds__extract_quarter
+ , subq_11.buy__ds__extract_month
+ , subq_11.buy__ds__extract_day
+ , subq_11.buy__ds__extract_dow
+ , subq_11.buy__ds__extract_doy
+ , subq_11.ds__day AS metric_time__day
+ , subq_11.ds__week AS metric_time__week
+ , subq_11.ds__month AS metric_time__month
+ , subq_11.ds__quarter AS metric_time__quarter
+ , subq_11.ds__year AS metric_time__year
+ , subq_11.ds__extract_year AS metric_time__extract_year
+ , subq_11.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_11.ds__extract_month AS metric_time__extract_month
+ , subq_11.ds__extract_day AS metric_time__extract_day
+ , subq_11.ds__extract_dow AS metric_time__extract_dow
+ , subq_11.ds__extract_doy AS metric_time__extract_doy
+ , subq_11.user
+ , subq_11.session_id
+ , subq_11.buy__user
+ , subq_11.buy__session_id
+ , subq_11.buys
+ , subq_11.buyers
FROM (
-- Read Elements From Semantic Model 'buys_source'
SELECT
@@ -479,33 +525,33 @@ FROM (
, buys_source_src_28000.user_id AS buy__user
, buys_source_src_28000.session_id AS buy__session_id
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_10
- ) subq_11
- ) subq_12
+ ) subq_11
+ ) subq_12
+ ) subq_13
ON
(
- subq_9.user = subq_12.user
+ subq_10.user = subq_13.user
) AND (
(
- subq_9.ds__day <= subq_12.ds__day
+ subq_10.ds__day <= subq_13.ds__day
) AND (
- subq_9.ds__day > DATE_ADD('day', -7, subq_12.ds__day)
+ subq_10.ds__day > DATE_ADD('day', -7, subq_13.ds__day)
)
)
- ) subq_13
- ) subq_14
- ) subq_15
+ ) subq_14
+ ) subq_15
+ ) subq_16
GROUP BY
- subq_15.metric_time__day
- , subq_15.visit__referrer_id
- ) subq_16
+ subq_16.metric_time__day
+ , subq_16.visit__referrer_id
+ ) subq_17
ON
(
- subq_5.visit__referrer_id = subq_16.visit__referrer_id
+ subq_5.visit__referrer_id = subq_17.visit__referrer_id
) AND (
- subq_5.metric_time__day = subq_16.metric_time__day
+ subq_5.metric_time__day = subq_17.metric_time__day
)
GROUP BY
- COALESCE(subq_5.metric_time__day, subq_16.metric_time__day)
- , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id)
-) subq_17
+ COALESCE(subq_5.metric_time__day, subq_17.metric_time__day)
+ , COALESCE(subq_5.visit__referrer_id, subq_17.visit__referrer_id)
+) subq_18
diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
index 585b86b4a1..f1bd0ff3ff 100644
--- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day) AS metric_time__day
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id
- , MAX(subq_23.visits) AS visits
- , MAX(subq_34.buys) AS buys
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day) AS metric_time__day
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_24.visits) AS visits
+ , MAX(subq_36.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Aggregate Measures
@@ -28,12 +28,12 @@ FROM (
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
- ) subq_21
+ ) subq_22
WHERE visit__referrer_id = 'ref_id_01'
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_23
+ ) subq_24
FULL OUTER JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day']
@@ -45,62 +45,72 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_27.visits) OVER (
+ FIRST_VALUE(subq_29.visits) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_27.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_29.visit__referrer_id) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_27.ds__day) OVER (
+ , FIRST_VALUE(subq_29.ds__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_27.metric_time__day) OVER (
+ , FIRST_VALUE(subq_29.metric_time__day) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_27.user) OVER (
+ , FIRST_VALUE(subq_29.user) OVER (
PARTITION BY
- subq_30.user
- , subq_30.ds__day
- , subq_30.mf_internal_uuid
- ORDER BY subq_27.ds__day DESC
+ subq_32.user
+ , subq_32.ds__day
+ , subq_32.mf_internal_uuid
+ ORDER BY subq_29.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_30.mf_internal_uuid AS mf_internal_uuid
- , subq_30.buys AS buys
+ , subq_32.mf_internal_uuid AS mf_internal_uuid
+ , subq_32.buys AS buys
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
- -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', '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
- , referrer_id AS visit__referrer_id
- , 1 AS visits
- FROM ***************************.fct_visits visits_source_src_28000
- WHERE DATE_TRUNC('day', ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
- ) subq_27
+ ds__day
+ , metric_time__day
+ , subq_27.user
+ , visit__referrer_id
+ , visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) AS metric_time__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_28000
+ WHERE DATE_TRUNC('day', ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
+ ) subq_27
+ WHERE visit__referrer_id = 'ref_id_01'
+ ) subq_29
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -111,29 +121,29 @@ FROM (
, 1 AS buys
, uuid() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_30
+ ) subq_32
ON
(
- subq_27.user = subq_30.user
+ subq_29.user = subq_32.user
) AND (
(
- subq_27.ds__day <= subq_30.ds__day
+ subq_29.ds__day <= subq_32.ds__day
) AND (
- subq_27.ds__day > DATE_ADD('day', -7, subq_30.ds__day)
+ subq_29.ds__day > DATE_ADD('day', -7, subq_32.ds__day)
)
)
- ) subq_31
+ ) subq_33
GROUP BY
metric_time__day
, visit__referrer_id
- ) subq_34
+ ) subq_36
ON
(
- subq_23.visit__referrer_id = subq_34.visit__referrer_id
+ subq_24.visit__referrer_id = subq_36.visit__referrer_id
) AND (
- subq_23.metric_time__day = subq_34.metric_time__day
+ subq_24.metric_time__day = subq_36.metric_time__day
)
GROUP BY
- COALESCE(subq_23.metric_time__day, subq_34.metric_time__day)
- , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id)
-) subq_35
+ COALESCE(subq_24.metric_time__day, subq_36.metric_time__day)
+ , COALESCE(subq_24.visit__referrer_id, subq_36.visit__referrer_id)
+) subq_37
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric__query_output.txt
new file mode 100644
index 0000000000..d59c3ac1da
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate
+------------------- ---------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_categorical_filter__query_output.txt
new file mode 100644
index 0000000000..e1e5bd822d
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_categorical_filter__query_output.txt
@@ -0,0 +1,5 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate
+------------------- -------------------- ---------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
+2020-01-03T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
new file mode 100644
index 0000000000..e3046748a3
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
@@ -0,0 +1,3 @@
+ visit_buy_conversions
+-----------------------
+ 3
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_time_constraint__query_output.txt
new file mode 100644
index 0000000000..3fb6f042e8
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_time_constraint__query_output.txt
@@ -0,0 +1,3 @@
+visit__referrer_id visit_buy_conversion_rate
+-------------------- ---------------------------
+fb_ad_1 1.5
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window__query_output.txt
new file mode 100644
index 0000000000..294fbf9259
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate_7days
+------------------- ---------------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window_and_time_constraint__query_output.txt
new file mode 100644
index 0000000000..b4958e8622
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window_and_time_constraint__query_output.txt
@@ -0,0 +1,4 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate_7days
+------------------- -------------------- ---------------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric__query_output.txt
new file mode 100644
index 0000000000..d59c3ac1da
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate
+------------------- ---------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_categorical_filter__query_output.txt
new file mode 100644
index 0000000000..e1e5bd822d
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_categorical_filter__query_output.txt
@@ -0,0 +1,5 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate
+------------------- -------------------- ---------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
+2020-01-03T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
new file mode 100644
index 0000000000..e3046748a3
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
@@ -0,0 +1,3 @@
+ visit_buy_conversions
+-----------------------
+ 3
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_time_constraint__query_output.txt
new file mode 100644
index 0000000000..3fb6f042e8
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_time_constraint__query_output.txt
@@ -0,0 +1,3 @@
+visit__referrer_id visit_buy_conversion_rate
+-------------------- ---------------------------
+fb_ad_1 1.5
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window__query_output.txt
new file mode 100644
index 0000000000..294fbf9259
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate_7days
+------------------- ---------------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window_and_time_constraint__query_output.txt
new file mode 100644
index 0000000000..b4958e8622
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window_and_time_constraint__query_output.txt
@@ -0,0 +1,4 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate_7days
+------------------- -------------------- ---------------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric__query_output.txt
new file mode 100644
index 0000000000..d59c3ac1da
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate
+------------------- ---------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_categorical_filter__query_output.txt
new file mode 100644
index 0000000000..e1e5bd822d
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_categorical_filter__query_output.txt
@@ -0,0 +1,5 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate
+------------------- -------------------- ---------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
+2020-01-03T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
new file mode 100644
index 0000000000..e3046748a3
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
@@ -0,0 +1,3 @@
+ visit_buy_conversions
+-----------------------
+ 3
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_time_constraint__query_output.txt
new file mode 100644
index 0000000000..3fb6f042e8
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_time_constraint__query_output.txt
@@ -0,0 +1,3 @@
+visit__referrer_id visit_buy_conversion_rate
+-------------------- ---------------------------
+fb_ad_1 1.5
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window__query_output.txt
new file mode 100644
index 0000000000..294fbf9259
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate_7days
+------------------- ---------------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window_and_time_constraint__query_output.txt
new file mode 100644
index 0000000000..b4958e8622
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window_and_time_constraint__query_output.txt
@@ -0,0 +1,4 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate_7days
+------------------- -------------------- ---------------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric__query_output.txt
new file mode 100644
index 0000000000..d59c3ac1da
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate
+------------------- ---------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_categorical_filter__query_output.txt
new file mode 100644
index 0000000000..e1e5bd822d
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_categorical_filter__query_output.txt
@@ -0,0 +1,5 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate
+------------------- -------------------- ---------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
+2020-01-03T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
new file mode 100644
index 0000000000..e3046748a3
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
@@ -0,0 +1,3 @@
+ visit_buy_conversions
+-----------------------
+ 3
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_time_constraint__query_output.txt
new file mode 100644
index 0000000000..3fb6f042e8
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_time_constraint__query_output.txt
@@ -0,0 +1,3 @@
+visit__referrer_id visit_buy_conversion_rate
+-------------------- ---------------------------
+fb_ad_1 1.5
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window__query_output.txt
new file mode 100644
index 0000000000..294fbf9259
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate_7days
+------------------- ---------------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window_and_time_constraint__query_output.txt
new file mode 100644
index 0000000000..b4958e8622
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window_and_time_constraint__query_output.txt
@@ -0,0 +1,4 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate_7days
+------------------- -------------------- ---------------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric__query_output.txt
new file mode 100644
index 0000000000..d59c3ac1da
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate
+------------------- ---------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_categorical_filter__query_output.txt
new file mode 100644
index 0000000000..e1e5bd822d
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_categorical_filter__query_output.txt
@@ -0,0 +1,5 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate
+------------------- -------------------- ---------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
+2020-01-03T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
new file mode 100644
index 0000000000..e3046748a3
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
@@ -0,0 +1,3 @@
+ visit_buy_conversions
+-----------------------
+ 3
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_time_constraint__query_output.txt
new file mode 100644
index 0000000000..3fb6f042e8
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_time_constraint__query_output.txt
@@ -0,0 +1,3 @@
+visit__referrer_id visit_buy_conversion_rate
+-------------------- ---------------------------
+fb_ad_1 1.5
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window__query_output.txt
new file mode 100644
index 0000000000..294fbf9259
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate_7days
+------------------- ---------------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window_and_time_constraint__query_output.txt
new file mode 100644
index 0000000000..b4958e8622
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window_and_time_constraint__query_output.txt
@@ -0,0 +1,4 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate_7days
+------------------- -------------------- ---------------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric__query_output.txt
new file mode 100644
index 0000000000..57e6611f5c
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric__query_output.txt
@@ -0,0 +1,10 @@
+METRIC_TIME__DAY VISIT_BUY_CONVERSION_RATE
+------------------- ---------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_categorical_filter__query_output.txt
new file mode 100644
index 0000000000..c8138396fe
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_categorical_filter__query_output.txt
@@ -0,0 +1,5 @@
+METRIC_TIME__DAY VISIT__REFERRER_ID VISIT_BUY_CONVERSION_RATE
+------------------- -------------------- ---------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
+2020-01-03T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
new file mode 100644
index 0000000000..9cbe5f4439
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
@@ -0,0 +1,3 @@
+ VISIT_BUY_CONVERSIONS
+-----------------------
+ 3
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_time_constraint__query_output.txt
new file mode 100644
index 0000000000..53b4574200
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_time_constraint__query_output.txt
@@ -0,0 +1,3 @@
+VISIT__REFERRER_ID VISIT_BUY_CONVERSION_RATE
+-------------------- ---------------------------
+fb_ad_1 1.5
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window__query_output.txt
new file mode 100644
index 0000000000..1d3f1dd15a
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window__query_output.txt
@@ -0,0 +1,10 @@
+METRIC_TIME__DAY VISIT_BUY_CONVERSION_RATE_7DAYS
+------------------- ---------------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window_and_time_constraint__query_output.txt
new file mode 100644
index 0000000000..fd1601ac58
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window_and_time_constraint__query_output.txt
@@ -0,0 +1,4 @@
+METRIC_TIME__DAY VISIT__REFERRER_ID VISIT_BUY_CONVERSION_RATE_7DAYS
+------------------- -------------------- ---------------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric__query_output.txt
new file mode 100644
index 0000000000..d59c3ac1da
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate
+------------------- ---------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_categorical_filter__query_output.txt
new file mode 100644
index 0000000000..e1e5bd822d
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_categorical_filter__query_output.txt
@@ -0,0 +1,5 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate
+------------------- -------------------- ---------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
+2020-01-03T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
new file mode 100644
index 0000000000..e3046748a3
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_filter_not_in_group_by__query_output.txt
@@ -0,0 +1,3 @@
+ visit_buy_conversions
+-----------------------
+ 3
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_time_constraint__query_output.txt
new file mode 100644
index 0000000000..3fb6f042e8
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_time_constraint__query_output.txt
@@ -0,0 +1,3 @@
+visit__referrer_id visit_buy_conversion_rate
+-------------------- ---------------------------
+fb_ad_1 1.5
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window__query_output.txt
new file mode 100644
index 0000000000..294fbf9259
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window__query_output.txt
@@ -0,0 +1,10 @@
+metric_time__day visit_buy_conversion_rate_7days
+------------------- ---------------------------------
+2020-01-01T00:00:00 0.50
+2020-01-02T00:00:00 0.50
+2020-01-03T00:00:00 0.67
+2020-01-04T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 1.00
+2020-01-10T00:00:00 1.00
+2020-01-12T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window_and_time_constraint__query_output.txt
new file mode 100644
index 0000000000..b4958e8622
--- /dev/null
+++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window_and_time_constraint__query_output.txt
@@ -0,0 +1,4 @@
+metric_time__day visit__referrer_id visit_buy_conversion_rate_7days
+------------------- -------------------- ---------------------------------
+2020-01-01T00:00:00 fb_ad_1 2
+2020-01-02T00:00:00 fb_ad_1 1
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml
index db32699106..bb350581db 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml
@@ -197,83 +197,71 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -281,80 +269,165 @@
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfpo_0.xml
index 116896e916..549e3e0d73 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfpo_0.xml
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfpo_0.xml
@@ -62,7 +62,7 @@
-
+
@@ -79,7 +79,7 @@
-
+
@@ -100,9 +100,9 @@
-
+
-
+
@@ -110,7 +110,7 @@
-
+
@@ -126,7 +126,7 @@
-
+
@@ -180,7 +180,7 @@
-
+
@@ -194,83 +194,71 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -278,80 +266,164 @@
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_query_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_query_filters__plan0.sql
index 485da5fb9b..144fda2068 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_query_filters__plan0.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_query_filters__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_27.metric_time__day
- , subq_27.user__home_state_latest
- , CAST(subq_27.buys AS FLOAT64) / CAST(NULLIF(subq_27.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate_7days
+ subq_29.metric_time__day
+ , subq_29.user__home_state_latest
+ , CAST(subq_29.buys AS FLOAT64) / CAST(NULLIF(subq_29.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day) AS metric_time__day
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest) AS user__home_state_latest
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day) AS metric_time__day
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest) AS user__home_state_latest
, MAX(subq_9.visits) AS visits
- , MAX(subq_26.buys) AS buys
+ , MAX(subq_28.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -180,453 +180,507 @@ FROM (
, user__home_state_latest
) subq_9
FULL OUTER JOIN (
- -- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- , SUM(subq_25.buys) AS buys
+ subq_27.metric_time__day
+ , subq_27.user__home_state_latest
+ , subq_27.buys
FROM (
- -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
+ -- Aggregate Measures
SELECT
- subq_24.metric_time__day
- , subq_24.user__home_state_latest
- , subq_24.buys
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ , SUM(subq_26.buys) AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_21.metric_time__day AS metric_time__day
- , subq_21.user AS user
- , subq_21.visit__referrer_id AS visit__referrer_id
- , subq_23.home_state_latest AS user__home_state_latest
- , subq_21.buys AS buys
+ subq_25.metric_time__day
+ , subq_25.user__home_state_latest
+ , subq_25.buys
FROM (
- -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
+ -- Join Standard Outputs
SELECT
- subq_20.metric_time__day
- , subq_20.user
- , subq_20.visit__referrer_id
- , subq_20.buys
+ subq_22.metric_time__day AS metric_time__day
+ , subq_22.user AS user
+ , subq_22.visit__referrer_id AS visit__referrer_id
+ , subq_24.home_state_latest AS user__home_state_latest
+ , subq_22.buys AS buys
FROM (
- -- Find conversions for user within the range of 7 day
+ -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
SELECT
- subq_19.ds__day
- , subq_19.metric_time__day
- , subq_19.user
- , subq_19.visit__referrer_id
- , subq_19.user__home_state_latest
- , subq_19.buys
- , subq_19.visits
+ subq_21.metric_time__day
+ , subq_21.user
+ , subq_21.visit__referrer_id
+ , subq_21.buys
FROM (
- -- Dedupe the fanout with mf_internal_uuid in the conversion data set
- SELECT DISTINCT
- FIRST_VALUE(subq_15.visits) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visits
- , FIRST_VALUE(subq_15.visit__referrer_id) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visit__referrer_id
- , FIRST_VALUE(subq_15.user__home_state_latest) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user__home_state_latest
- , FIRST_VALUE(subq_15.ds__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS ds__day
- , FIRST_VALUE(subq_15.metric_time__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS metric_time__day
- , FIRST_VALUE(subq_15.user) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user
- , subq_18.mf_internal_uuid AS mf_internal_uuid
- , subq_18.buys AS buys
+ -- Find conversions for user within the range of 7 day
+ SELECT
+ subq_20.ds__day
+ , subq_20.metric_time__day
+ , subq_20.user
+ , subq_20.visit__referrer_id
+ , subq_20.user__home_state_latest
+ , subq_20.buys
+ , subq_20.visits
FROM (
- -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
- SELECT
- subq_14.ds__day
- , subq_14.metric_time__day
- , subq_14.user
- , subq_14.visit__referrer_id
- , subq_14.user__home_state_latest
- , subq_14.visits
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_16.visits) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_16.visit__referrer_id) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visit__referrer_id
+ , FIRST_VALUE(subq_16.user__home_state_latest) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user__home_state_latest
+ , FIRST_VALUE(subq_16.ds__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_16.metric_time__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_16.user) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_19.mf_internal_uuid AS mf_internal_uuid
+ , subq_19.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_11.ds__day AS ds__day
- , subq_11.ds__week AS ds__week
- , subq_11.ds__month AS ds__month
- , subq_11.ds__quarter AS ds__quarter
- , subq_11.ds__year AS ds__year
- , subq_11.ds__extract_year AS ds__extract_year
- , subq_11.ds__extract_quarter AS ds__extract_quarter
- , subq_11.ds__extract_month AS ds__extract_month
- , subq_11.ds__extract_day AS ds__extract_day
- , subq_11.ds__extract_dow AS ds__extract_dow
- , subq_11.ds__extract_doy AS ds__extract_doy
- , subq_11.visit__ds__day AS visit__ds__day
- , subq_11.visit__ds__week AS visit__ds__week
- , subq_11.visit__ds__month AS visit__ds__month
- , subq_11.visit__ds__quarter AS visit__ds__quarter
- , subq_11.visit__ds__year AS visit__ds__year
- , subq_11.visit__ds__extract_year AS visit__ds__extract_year
- , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
- , subq_11.visit__ds__extract_month AS visit__ds__extract_month
- , subq_11.visit__ds__extract_day AS visit__ds__extract_day
- , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
- , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
- , subq_11.metric_time__day AS metric_time__day
- , subq_11.metric_time__week AS metric_time__week
- , subq_11.metric_time__month AS metric_time__month
- , subq_11.metric_time__quarter AS metric_time__quarter
- , subq_11.metric_time__year AS metric_time__year
- , subq_11.metric_time__extract_year AS metric_time__extract_year
- , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
- , subq_11.metric_time__extract_month AS metric_time__extract_month
- , subq_11.metric_time__extract_day AS metric_time__extract_day
- , subq_11.metric_time__extract_dow AS metric_time__extract_dow
- , subq_11.metric_time__extract_doy AS metric_time__extract_doy
- , subq_11.user AS user
- , subq_11.session AS session
- , subq_11.visit__user AS visit__user
- , subq_11.visit__session AS visit__session
- , subq_11.referrer_id AS referrer_id
- , subq_11.visit__referrer_id AS visit__referrer_id
- , subq_13.home_state_latest AS user__home_state_latest
- , subq_11.visits AS visits
- , subq_11.visitors AS visitors
+ subq_15.ds__day
+ , subq_15.metric_time__day
+ , subq_15.user
+ , subq_15.visit__referrer_id
+ , subq_15.user__home_state_latest
+ , subq_15.visits
FROM (
- -- Metric Time Dimension 'ds'
+ -- Constrain Output with WHERE
SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.visit__ds__day
- , subq_10.visit__ds__week
- , subq_10.visit__ds__month
- , subq_10.visit__ds__quarter
- , subq_10.visit__ds__year
- , subq_10.visit__ds__extract_year
- , subq_10.visit__ds__extract_quarter
- , subq_10.visit__ds__extract_month
- , subq_10.visit__ds__extract_day
- , subq_10.visit__ds__extract_dow
- , subq_10.visit__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session
- , subq_10.visit__user
- , subq_10.visit__session
- , subq_10.referrer_id
- , subq_10.visit__referrer_id
- , subq_10.visits
- , subq_10.visitors
+ subq_14.ds__day
+ , subq_14.ds__week
+ , subq_14.ds__month
+ , subq_14.ds__quarter
+ , subq_14.ds__year
+ , subq_14.ds__extract_year
+ , subq_14.ds__extract_quarter
+ , subq_14.ds__extract_month
+ , subq_14.ds__extract_day
+ , subq_14.ds__extract_dow
+ , subq_14.ds__extract_doy
+ , subq_14.visit__ds__day
+ , subq_14.visit__ds__week
+ , subq_14.visit__ds__month
+ , subq_14.visit__ds__quarter
+ , subq_14.visit__ds__year
+ , subq_14.visit__ds__extract_year
+ , subq_14.visit__ds__extract_quarter
+ , subq_14.visit__ds__extract_month
+ , subq_14.visit__ds__extract_day
+ , subq_14.visit__ds__extract_dow
+ , subq_14.visit__ds__extract_doy
+ , subq_14.metric_time__day
+ , subq_14.metric_time__week
+ , subq_14.metric_time__month
+ , subq_14.metric_time__quarter
+ , subq_14.metric_time__year
+ , subq_14.metric_time__extract_year
+ , subq_14.metric_time__extract_quarter
+ , subq_14.metric_time__extract_month
+ , subq_14.metric_time__extract_day
+ , subq_14.metric_time__extract_dow
+ , subq_14.metric_time__extract_doy
+ , subq_14.user
+ , subq_14.session
+ , subq_14.visit__user
+ , subq_14.visit__session
+ , subq_14.referrer_id
+ , subq_14.visit__referrer_id
+ , subq_14.user__home_state_latest
+ , subq_14.visits
+ , subq_14.visitors
FROM (
- -- Read Elements From Semantic Model 'visits_source'
+ -- Join Standard Outputs
SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
- , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
- , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
- , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
- , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
- , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_10
- ) subq_11
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
- SELECT
- subq_12.user
- , subq_12.home_state_latest
- FROM (
- -- Read Elements From Semantic Model 'users_latest'
- SELECT
- DATETIME_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day
- , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week
- , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month
- , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter
- , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow
- , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATETIME_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day
- , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week
- , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month
- , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter
- , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow
- , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
- ) subq_12
- ) subq_13
- ON
- subq_11.user = subq_13.user
- ) subq_14
- ) subq_15
- INNER JOIN (
- -- Add column with generated UUID
- SELECT
- subq_17.ds__day
- , subq_17.ds__week
- , subq_17.ds__month
- , subq_17.ds__quarter
- , subq_17.ds__year
- , subq_17.ds__extract_year
- , subq_17.ds__extract_quarter
- , subq_17.ds__extract_month
- , subq_17.ds__extract_day
- , subq_17.ds__extract_dow
- , subq_17.ds__extract_doy
- , subq_17.buy__ds__day
- , subq_17.buy__ds__week
- , subq_17.buy__ds__month
- , subq_17.buy__ds__quarter
- , subq_17.buy__ds__year
- , subq_17.buy__ds__extract_year
- , subq_17.buy__ds__extract_quarter
- , subq_17.buy__ds__extract_month
- , subq_17.buy__ds__extract_day
- , subq_17.buy__ds__extract_dow
- , subq_17.buy__ds__extract_doy
- , subq_17.metric_time__day
- , subq_17.metric_time__week
- , subq_17.metric_time__month
- , subq_17.metric_time__quarter
- , subq_17.metric_time__year
- , subq_17.metric_time__extract_year
- , subq_17.metric_time__extract_quarter
- , subq_17.metric_time__extract_month
- , subq_17.metric_time__extract_day
- , subq_17.metric_time__extract_dow
- , subq_17.metric_time__extract_doy
- , subq_17.user
- , subq_17.session_id
- , subq_17.buy__user
- , subq_17.buy__session_id
- , subq_17.buys
- , subq_17.buyers
- , GENERATE_UUID() AS mf_internal_uuid
- FROM (
- -- Metric Time Dimension 'ds'
+ subq_11.ds__day AS ds__day
+ , subq_11.ds__week AS ds__week
+ , subq_11.ds__month AS ds__month
+ , subq_11.ds__quarter AS ds__quarter
+ , subq_11.ds__year AS ds__year
+ , subq_11.ds__extract_year AS ds__extract_year
+ , subq_11.ds__extract_quarter AS ds__extract_quarter
+ , subq_11.ds__extract_month AS ds__extract_month
+ , subq_11.ds__extract_day AS ds__extract_day
+ , subq_11.ds__extract_dow AS ds__extract_dow
+ , subq_11.ds__extract_doy AS ds__extract_doy
+ , subq_11.visit__ds__day AS visit__ds__day
+ , subq_11.visit__ds__week AS visit__ds__week
+ , subq_11.visit__ds__month AS visit__ds__month
+ , subq_11.visit__ds__quarter AS visit__ds__quarter
+ , subq_11.visit__ds__year AS visit__ds__year
+ , subq_11.visit__ds__extract_year AS visit__ds__extract_year
+ , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
+ , subq_11.visit__ds__extract_month AS visit__ds__extract_month
+ , subq_11.visit__ds__extract_day AS visit__ds__extract_day
+ , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
+ , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
+ , subq_11.metric_time__day AS metric_time__day
+ , subq_11.metric_time__week AS metric_time__week
+ , subq_11.metric_time__month AS metric_time__month
+ , subq_11.metric_time__quarter AS metric_time__quarter
+ , subq_11.metric_time__year AS metric_time__year
+ , subq_11.metric_time__extract_year AS metric_time__extract_year
+ , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_11.metric_time__extract_month AS metric_time__extract_month
+ , subq_11.metric_time__extract_day AS metric_time__extract_day
+ , subq_11.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_11.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_11.user AS user
+ , subq_11.session AS session
+ , subq_11.visit__user AS visit__user
+ , subq_11.visit__session AS visit__session
+ , subq_11.referrer_id AS referrer_id
+ , subq_11.visit__referrer_id AS visit__referrer_id
+ , subq_13.home_state_latest AS user__home_state_latest
+ , subq_11.visits AS visits
+ , subq_11.visitors AS visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.visit__ds__day
+ , subq_10.visit__ds__week
+ , subq_10.visit__ds__month
+ , subq_10.visit__ds__quarter
+ , subq_10.visit__ds__year
+ , subq_10.visit__ds__extract_year
+ , subq_10.visit__ds__extract_quarter
+ , subq_10.visit__ds__extract_month
+ , subq_10.visit__ds__extract_day
+ , subq_10.visit__ds__extract_dow
+ , subq_10.visit__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session
+ , subq_10.visit__user
+ , subq_10.visit__session
+ , subq_10.referrer_id
+ , subq_10.visit__referrer_id
+ , subq_10.visits
+ , subq_10.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day
+ , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week
+ , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month
+ , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter
+ , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow
+ , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_10
+ ) subq_11
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_12.user
+ , subq_12.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATETIME_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day
+ , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week
+ , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month
+ , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter
+ , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow
+ , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATETIME_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day
+ , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week
+ , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month
+ , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter
+ , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow
+ , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_12
+ ) subq_13
+ ON
+ subq_11.user = subq_13.user
+ ) subq_14
+ WHERE visit__referrer_id = '123456'
+ ) subq_15
+ ) subq_16
+ INNER JOIN (
+ -- Add column with generated UUID
SELECT
- subq_16.ds__day
- , subq_16.ds__week
- , subq_16.ds__month
- , subq_16.ds__quarter
- , subq_16.ds__year
- , subq_16.ds__extract_year
- , subq_16.ds__extract_quarter
- , subq_16.ds__extract_month
- , subq_16.ds__extract_day
- , subq_16.ds__extract_dow
- , subq_16.ds__extract_doy
- , subq_16.buy__ds__day
- , subq_16.buy__ds__week
- , subq_16.buy__ds__month
- , subq_16.buy__ds__quarter
- , subq_16.buy__ds__year
- , subq_16.buy__ds__extract_year
- , subq_16.buy__ds__extract_quarter
- , subq_16.buy__ds__extract_month
- , subq_16.buy__ds__extract_day
- , subq_16.buy__ds__extract_dow
- , subq_16.buy__ds__extract_doy
- , subq_16.ds__day AS metric_time__day
- , subq_16.ds__week AS metric_time__week
- , subq_16.ds__month AS metric_time__month
- , subq_16.ds__quarter AS metric_time__quarter
- , subq_16.ds__year AS metric_time__year
- , subq_16.ds__extract_year AS metric_time__extract_year
- , subq_16.ds__extract_quarter AS metric_time__extract_quarter
- , subq_16.ds__extract_month AS metric_time__extract_month
- , subq_16.ds__extract_day AS metric_time__extract_day
- , subq_16.ds__extract_dow AS metric_time__extract_dow
- , subq_16.ds__extract_doy AS metric_time__extract_doy
- , subq_16.user
- , subq_16.session_id
- , subq_16.buy__user
- , subq_16.buy__session_id
- , subq_16.buys
- , subq_16.buyers
+ subq_18.ds__day
+ , subq_18.ds__week
+ , subq_18.ds__month
+ , subq_18.ds__quarter
+ , subq_18.ds__year
+ , subq_18.ds__extract_year
+ , subq_18.ds__extract_quarter
+ , subq_18.ds__extract_month
+ , subq_18.ds__extract_day
+ , subq_18.ds__extract_dow
+ , subq_18.ds__extract_doy
+ , subq_18.buy__ds__day
+ , subq_18.buy__ds__week
+ , subq_18.buy__ds__month
+ , subq_18.buy__ds__quarter
+ , subq_18.buy__ds__year
+ , subq_18.buy__ds__extract_year
+ , subq_18.buy__ds__extract_quarter
+ , subq_18.buy__ds__extract_month
+ , subq_18.buy__ds__extract_day
+ , subq_18.buy__ds__extract_dow
+ , subq_18.buy__ds__extract_doy
+ , subq_18.metric_time__day
+ , subq_18.metric_time__week
+ , subq_18.metric_time__month
+ , subq_18.metric_time__quarter
+ , subq_18.metric_time__year
+ , subq_18.metric_time__extract_year
+ , subq_18.metric_time__extract_quarter
+ , subq_18.metric_time__extract_month
+ , subq_18.metric_time__extract_day
+ , subq_18.metric_time__extract_dow
+ , subq_18.metric_time__extract_doy
+ , subq_18.user
+ , subq_18.session_id
+ , subq_18.buy__user
+ , subq_18.buy__session_id
+ , subq_18.buys
+ , subq_18.buyers
+ , GENERATE_UUID() AS mf_internal_uuid
FROM (
- -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS buys
- , buys_source_src_28000.user_id AS buyers
- , DATETIME_TRUNC(buys_source_src_28000.ds, day) AS ds__day
- , DATETIME_TRUNC(buys_source_src_28000.ds, isoweek) AS ds__week
- , DATETIME_TRUNC(buys_source_src_28000.ds, month) AS ds__month
- , DATETIME_TRUNC(buys_source_src_28000.ds, quarter) AS ds__quarter
- , DATETIME_TRUNC(buys_source_src_28000.ds, year) AS ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
- , IF(EXTRACT(dayofweek FROM buys_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM buys_source_src_28000.ds) - 1) AS ds__extract_dow
- , EXTRACT(dayofyear FROM buys_source_src_28000.ds) AS ds__extract_doy
- , DATETIME_TRUNC(buys_source_src_28000.ds, day) AS buy__ds__day
- , DATETIME_TRUNC(buys_source_src_28000.ds, isoweek) AS buy__ds__week
- , DATETIME_TRUNC(buys_source_src_28000.ds, month) AS buy__ds__month
- , DATETIME_TRUNC(buys_source_src_28000.ds, quarter) AS buy__ds__quarter
- , DATETIME_TRUNC(buys_source_src_28000.ds, year) AS buy__ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
- , IF(EXTRACT(dayofweek FROM buys_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM buys_source_src_28000.ds) - 1) AS buy__ds__extract_dow
- , EXTRACT(dayofyear FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
- , buys_source_src_28000.user_id AS user
- , buys_source_src_28000.session_id
- , buys_source_src_28000.user_id AS buy__user
- , buys_source_src_28000.session_id AS buy__session_id
- FROM ***************************.fct_buys buys_source_src_28000
- ) subq_16
- ) subq_17
- ) subq_18
- ON
- (
- subq_15.user = subq_18.user
- ) AND (
+ subq_17.ds__day
+ , subq_17.ds__week
+ , subq_17.ds__month
+ , subq_17.ds__quarter
+ , subq_17.ds__year
+ , subq_17.ds__extract_year
+ , subq_17.ds__extract_quarter
+ , subq_17.ds__extract_month
+ , subq_17.ds__extract_day
+ , subq_17.ds__extract_dow
+ , subq_17.ds__extract_doy
+ , subq_17.buy__ds__day
+ , subq_17.buy__ds__week
+ , subq_17.buy__ds__month
+ , subq_17.buy__ds__quarter
+ , subq_17.buy__ds__year
+ , subq_17.buy__ds__extract_year
+ , subq_17.buy__ds__extract_quarter
+ , subq_17.buy__ds__extract_month
+ , subq_17.buy__ds__extract_day
+ , subq_17.buy__ds__extract_dow
+ , subq_17.buy__ds__extract_doy
+ , subq_17.ds__day AS metric_time__day
+ , subq_17.ds__week AS metric_time__week
+ , subq_17.ds__month AS metric_time__month
+ , subq_17.ds__quarter AS metric_time__quarter
+ , subq_17.ds__year AS metric_time__year
+ , subq_17.ds__extract_year AS metric_time__extract_year
+ , subq_17.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_17.ds__extract_month AS metric_time__extract_month
+ , subq_17.ds__extract_day AS metric_time__extract_day
+ , subq_17.ds__extract_dow AS metric_time__extract_dow
+ , subq_17.ds__extract_doy AS metric_time__extract_doy
+ , subq_17.user
+ , subq_17.session_id
+ , subq_17.buy__user
+ , subq_17.buy__session_id
+ , subq_17.buys
+ , subq_17.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATETIME_TRUNC(buys_source_src_28000.ds, day) AS ds__day
+ , DATETIME_TRUNC(buys_source_src_28000.ds, isoweek) AS ds__week
+ , DATETIME_TRUNC(buys_source_src_28000.ds, month) AS ds__month
+ , DATETIME_TRUNC(buys_source_src_28000.ds, quarter) AS ds__quarter
+ , DATETIME_TRUNC(buys_source_src_28000.ds, year) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , IF(EXTRACT(dayofweek FROM buys_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM buys_source_src_28000.ds) - 1) AS ds__extract_dow
+ , EXTRACT(dayofyear FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATETIME_TRUNC(buys_source_src_28000.ds, day) AS buy__ds__day
+ , DATETIME_TRUNC(buys_source_src_28000.ds, isoweek) AS buy__ds__week
+ , DATETIME_TRUNC(buys_source_src_28000.ds, month) AS buy__ds__month
+ , DATETIME_TRUNC(buys_source_src_28000.ds, quarter) AS buy__ds__quarter
+ , DATETIME_TRUNC(buys_source_src_28000.ds, year) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , IF(EXTRACT(dayofweek FROM buys_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM buys_source_src_28000.ds) - 1) AS buy__ds__extract_dow
+ , EXTRACT(dayofyear FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_17
+ ) subq_18
+ ) subq_19
+ ON
(
- subq_15.ds__day <= subq_18.ds__day
+ subq_16.user = subq_19.user
) AND (
- subq_15.ds__day > DATE_SUB(CAST(subq_18.ds__day AS DATETIME), INTERVAL 7 day)
+ (
+ subq_16.ds__day <= subq_19.ds__day
+ ) AND (
+ subq_16.ds__day > DATE_SUB(CAST(subq_19.ds__day AS DATETIME), INTERVAL 7 day)
+ )
)
- )
- ) subq_19
- ) subq_20
- ) subq_21
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
- SELECT
- subq_22.user
- , subq_22.home_state_latest
- FROM (
- -- Read Elements From Semantic Model 'users_latest'
- SELECT
- DATETIME_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day
- , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week
- , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month
- , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter
- , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow
- , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATETIME_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day
- , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week
- , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month
- , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter
- , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow
- , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_20
+ ) subq_21
) subq_22
- ) subq_23
- ON
- subq_21.user = subq_23.user
- ) subq_24
- ) subq_25
- GROUP BY
- metric_time__day
- , user__home_state_latest
- ) subq_26
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_23.user
+ , subq_23.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATETIME_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day
+ , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week
+ , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month
+ , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter
+ , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow
+ , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATETIME_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day
+ , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week
+ , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month
+ , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter
+ , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow
+ , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_23
+ ) subq_24
+ ON
+ subq_22.user = subq_24.user
+ ) subq_25
+ ) subq_26
+ GROUP BY
+ metric_time__day
+ , user__home_state_latest
+ ) subq_27
+ ) subq_28
ON
(
- subq_9.user__home_state_latest = subq_26.user__home_state_latest
+ subq_9.user__home_state_latest = subq_28.user__home_state_latest
) AND (
- subq_9.metric_time__day = subq_26.metric_time__day
+ subq_9.metric_time__day = subq_28.metric_time__day
)
GROUP BY
metric_time__day
, user__home_state_latest
-) subq_27
+) subq_29
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_query_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_query_filters__plan0_optimized.sql
index 2f20ea05f2..d3c49fc952 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_query_filters__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_query_filters__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day) AS metric_time__day
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest) AS user__home_state_latest
- , MAX(subq_37.visits) AS visits
- , MAX(subq_54.buys) AS buys
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day) AS metric_time__day
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest) AS user__home_state_latest
+ , MAX(subq_39.visits) AS visits
+ , MAX(subq_58.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'metric_time__day']
@@ -22,10 +22,10 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_30.metric_time__day AS metric_time__day
- , subq_30.visit__referrer_id AS visit__referrer_id
+ subq_32.metric_time__day AS metric_time__day
+ , subq_32.visit__referrer_id AS visit__referrer_id
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_30.visits AS visits
+ , subq_32.visits AS visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
@@ -36,104 +36,116 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_30
+ ) subq_32
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_30.user = users_latest_src_28000.user_id
- ) subq_34
+ subq_32.user = users_latest_src_28000.user_id
+ ) subq_36
WHERE visit__referrer_id = '123456'
GROUP BY
metric_time__day
, user__home_state_latest
- ) subq_37
+ ) subq_39
FULL OUTER JOIN (
-- Join Standard Outputs
-- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
-- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_47.metric_time__day AS metric_time__day
+ subq_50.metric_time__day AS metric_time__day
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , SUM(subq_47.buys) AS buys
+ , SUM(subq_50.buys) AS buys
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_43.visits) OVER (
+ FIRST_VALUE(subq_46.visits) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_43.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_46.visit__referrer_id) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_43.user__home_state_latest) OVER (
+ , FIRST_VALUE(subq_46.user__home_state_latest) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user__home_state_latest
- , FIRST_VALUE(subq_43.ds__day) OVER (
+ , FIRST_VALUE(subq_46.ds__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_43.metric_time__day) OVER (
+ , FIRST_VALUE(subq_46.metric_time__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_43.user) OVER (
+ , FIRST_VALUE(subq_46.user) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_46.mf_internal_uuid AS mf_internal_uuid
- , subq_46.buys AS buys
+ , subq_49.mf_internal_uuid AS mf_internal_uuid
+ , subq_49.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_39.ds__day AS ds__day
- , subq_39.metric_time__day AS metric_time__day
- , subq_39.user AS user
- , subq_39.visit__referrer_id AS visit__referrer_id
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_39.visits AS visits
+ ds__day
+ , metric_time__day
+ , subq_44.user
+ , visit__referrer_id
+ , user__home_state_latest
+ , visits
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
+ -- Join Standard Outputs
SELECT
- DATETIME_TRUNC(ds, day) AS ds__day
- , 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_39
- LEFT OUTER JOIN
- ***************************.dim_users_latest users_latest_src_28000
- ON
- subq_39.user = users_latest_src_28000.user_id
- ) subq_43
+ subq_41.ds__day AS ds__day
+ , subq_41.metric_time__day AS metric_time__day
+ , subq_41.user AS user
+ , subq_41.visit__referrer_id AS visit__referrer_id
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , subq_41.visits AS visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATETIME_TRUNC(ds, day) AS ds__day
+ , 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_41
+ LEFT OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_28000
+ ON
+ subq_41.user = users_latest_src_28000.user_id
+ ) subq_44
+ WHERE visit__referrer_id = '123456'
+ ) subq_46
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -144,33 +156,33 @@ FROM (
, 1 AS buys
, GENERATE_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_46
+ ) subq_49
ON
(
- subq_43.user = subq_46.user
+ subq_46.user = subq_49.user
) AND (
(
- subq_43.ds__day <= subq_46.ds__day
+ subq_46.ds__day <= subq_49.ds__day
) AND (
- subq_43.ds__day > DATE_SUB(CAST(subq_46.ds__day AS DATETIME), INTERVAL 7 day)
+ subq_46.ds__day > DATE_SUB(CAST(subq_49.ds__day AS DATETIME), INTERVAL 7 day)
)
)
- ) subq_47
+ ) subq_50
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_47.user = users_latest_src_28000.user_id
+ subq_50.user = users_latest_src_28000.user_id
GROUP BY
metric_time__day
, user__home_state_latest
- ) subq_54
+ ) subq_58
ON
(
- subq_37.user__home_state_latest = subq_54.user__home_state_latest
+ subq_39.user__home_state_latest = subq_58.user__home_state_latest
) AND (
- subq_37.metric_time__day = subq_54.metric_time__day
+ subq_39.metric_time__day = subq_58.metric_time__day
)
GROUP BY
metric_time__day
, user__home_state_latest
-) subq_55
+) subq_59
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_query_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_query_filters__plan0.sql
index 72eadd1d20..d1e83c11f4 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_query_filters__plan0.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_query_filters__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_27.metric_time__day
- , subq_27.user__home_state_latest
- , CAST(subq_27.buys AS DOUBLE) / CAST(NULLIF(subq_27.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_29.metric_time__day
+ , subq_29.user__home_state_latest
+ , CAST(subq_29.buys AS DOUBLE) / CAST(NULLIF(subq_29.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day) AS metric_time__day
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest) AS user__home_state_latest
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day) AS metric_time__day
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest) AS user__home_state_latest
, MAX(subq_9.visits) AS visits
- , MAX(subq_26.buys) AS buys
+ , MAX(subq_28.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -180,453 +180,507 @@ FROM (
, subq_8.user__home_state_latest
) subq_9
FULL OUTER JOIN (
- -- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- , SUM(subq_25.buys) AS buys
+ subq_27.metric_time__day
+ , subq_27.user__home_state_latest
+ , subq_27.buys
FROM (
- -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
+ -- Aggregate Measures
SELECT
- subq_24.metric_time__day
- , subq_24.user__home_state_latest
- , subq_24.buys
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ , SUM(subq_26.buys) AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_21.metric_time__day AS metric_time__day
- , subq_21.user AS user
- , subq_21.visit__referrer_id AS visit__referrer_id
- , subq_23.home_state_latest AS user__home_state_latest
- , subq_21.buys AS buys
+ subq_25.metric_time__day
+ , subq_25.user__home_state_latest
+ , subq_25.buys
FROM (
- -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
+ -- Join Standard Outputs
SELECT
- subq_20.metric_time__day
- , subq_20.user
- , subq_20.visit__referrer_id
- , subq_20.buys
+ subq_22.metric_time__day AS metric_time__day
+ , subq_22.user AS user
+ , subq_22.visit__referrer_id AS visit__referrer_id
+ , subq_24.home_state_latest AS user__home_state_latest
+ , subq_22.buys AS buys
FROM (
- -- Find conversions for user within the range of 7 day
+ -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
SELECT
- subq_19.ds__day
- , subq_19.metric_time__day
- , subq_19.user
- , subq_19.visit__referrer_id
- , subq_19.user__home_state_latest
- , subq_19.buys
- , subq_19.visits
+ subq_21.metric_time__day
+ , subq_21.user
+ , subq_21.visit__referrer_id
+ , subq_21.buys
FROM (
- -- Dedupe the fanout with mf_internal_uuid in the conversion data set
- SELECT DISTINCT
- FIRST_VALUE(subq_15.visits) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visits
- , FIRST_VALUE(subq_15.visit__referrer_id) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visit__referrer_id
- , FIRST_VALUE(subq_15.user__home_state_latest) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user__home_state_latest
- , FIRST_VALUE(subq_15.ds__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS ds__day
- , FIRST_VALUE(subq_15.metric_time__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS metric_time__day
- , FIRST_VALUE(subq_15.user) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user
- , subq_18.mf_internal_uuid AS mf_internal_uuid
- , subq_18.buys AS buys
+ -- Find conversions for user within the range of 7 day
+ SELECT
+ subq_20.ds__day
+ , subq_20.metric_time__day
+ , subq_20.user
+ , subq_20.visit__referrer_id
+ , subq_20.user__home_state_latest
+ , subq_20.buys
+ , subq_20.visits
FROM (
- -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
- SELECT
- subq_14.ds__day
- , subq_14.metric_time__day
- , subq_14.user
- , subq_14.visit__referrer_id
- , subq_14.user__home_state_latest
- , subq_14.visits
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_16.visits) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_16.visit__referrer_id) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visit__referrer_id
+ , FIRST_VALUE(subq_16.user__home_state_latest) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user__home_state_latest
+ , FIRST_VALUE(subq_16.ds__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_16.metric_time__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_16.user) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_19.mf_internal_uuid AS mf_internal_uuid
+ , subq_19.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_11.ds__day AS ds__day
- , subq_11.ds__week AS ds__week
- , subq_11.ds__month AS ds__month
- , subq_11.ds__quarter AS ds__quarter
- , subq_11.ds__year AS ds__year
- , subq_11.ds__extract_year AS ds__extract_year
- , subq_11.ds__extract_quarter AS ds__extract_quarter
- , subq_11.ds__extract_month AS ds__extract_month
- , subq_11.ds__extract_day AS ds__extract_day
- , subq_11.ds__extract_dow AS ds__extract_dow
- , subq_11.ds__extract_doy AS ds__extract_doy
- , subq_11.visit__ds__day AS visit__ds__day
- , subq_11.visit__ds__week AS visit__ds__week
- , subq_11.visit__ds__month AS visit__ds__month
- , subq_11.visit__ds__quarter AS visit__ds__quarter
- , subq_11.visit__ds__year AS visit__ds__year
- , subq_11.visit__ds__extract_year AS visit__ds__extract_year
- , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
- , subq_11.visit__ds__extract_month AS visit__ds__extract_month
- , subq_11.visit__ds__extract_day AS visit__ds__extract_day
- , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
- , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
- , subq_11.metric_time__day AS metric_time__day
- , subq_11.metric_time__week AS metric_time__week
- , subq_11.metric_time__month AS metric_time__month
- , subq_11.metric_time__quarter AS metric_time__quarter
- , subq_11.metric_time__year AS metric_time__year
- , subq_11.metric_time__extract_year AS metric_time__extract_year
- , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
- , subq_11.metric_time__extract_month AS metric_time__extract_month
- , subq_11.metric_time__extract_day AS metric_time__extract_day
- , subq_11.metric_time__extract_dow AS metric_time__extract_dow
- , subq_11.metric_time__extract_doy AS metric_time__extract_doy
- , subq_11.user AS user
- , subq_11.session AS session
- , subq_11.visit__user AS visit__user
- , subq_11.visit__session AS visit__session
- , subq_11.referrer_id AS referrer_id
- , subq_11.visit__referrer_id AS visit__referrer_id
- , subq_13.home_state_latest AS user__home_state_latest
- , subq_11.visits AS visits
- , subq_11.visitors AS visitors
+ subq_15.ds__day
+ , subq_15.metric_time__day
+ , subq_15.user
+ , subq_15.visit__referrer_id
+ , subq_15.user__home_state_latest
+ , subq_15.visits
FROM (
- -- Metric Time Dimension 'ds'
- SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.visit__ds__day
- , subq_10.visit__ds__week
- , subq_10.visit__ds__month
- , subq_10.visit__ds__quarter
- , subq_10.visit__ds__year
- , subq_10.visit__ds__extract_year
- , subq_10.visit__ds__extract_quarter
- , subq_10.visit__ds__extract_month
- , subq_10.visit__ds__extract_day
- , subq_10.visit__ds__extract_dow
- , subq_10.visit__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session
- , subq_10.visit__user
- , subq_10.visit__session
- , subq_10.referrer_id
- , subq_10.visit__referrer_id
- , subq_10.visits
- , subq_10.visitors
- FROM (
- -- Read Elements From Semantic Model 'visits_source'
- SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_10
- ) subq_11
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
+ -- Constrain Output with WHERE
SELECT
- subq_12.user
- , subq_12.home_state_latest
+ subq_14.ds__day
+ , subq_14.ds__week
+ , subq_14.ds__month
+ , subq_14.ds__quarter
+ , subq_14.ds__year
+ , subq_14.ds__extract_year
+ , subq_14.ds__extract_quarter
+ , subq_14.ds__extract_month
+ , subq_14.ds__extract_day
+ , subq_14.ds__extract_dow
+ , subq_14.ds__extract_doy
+ , subq_14.visit__ds__day
+ , subq_14.visit__ds__week
+ , subq_14.visit__ds__month
+ , subq_14.visit__ds__quarter
+ , subq_14.visit__ds__year
+ , subq_14.visit__ds__extract_year
+ , subq_14.visit__ds__extract_quarter
+ , subq_14.visit__ds__extract_month
+ , subq_14.visit__ds__extract_day
+ , subq_14.visit__ds__extract_dow
+ , subq_14.visit__ds__extract_doy
+ , subq_14.metric_time__day
+ , subq_14.metric_time__week
+ , subq_14.metric_time__month
+ , subq_14.metric_time__quarter
+ , subq_14.metric_time__year
+ , subq_14.metric_time__extract_year
+ , subq_14.metric_time__extract_quarter
+ , subq_14.metric_time__extract_month
+ , subq_14.metric_time__extract_day
+ , subq_14.metric_time__extract_dow
+ , subq_14.metric_time__extract_doy
+ , subq_14.user
+ , subq_14.session
+ , subq_14.visit__user
+ , subq_14.visit__session
+ , subq_14.referrer_id
+ , subq_14.visit__referrer_id
+ , subq_14.user__home_state_latest
+ , subq_14.visits
+ , subq_14.visitors
FROM (
- -- Read Elements From Semantic Model 'users_latest'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
- ) subq_12
- ) subq_13
- ON
- subq_11.user = subq_13.user
- ) subq_14
- ) subq_15
- INNER JOIN (
- -- Add column with generated UUID
- SELECT
- subq_17.ds__day
- , subq_17.ds__week
- , subq_17.ds__month
- , subq_17.ds__quarter
- , subq_17.ds__year
- , subq_17.ds__extract_year
- , subq_17.ds__extract_quarter
- , subq_17.ds__extract_month
- , subq_17.ds__extract_day
- , subq_17.ds__extract_dow
- , subq_17.ds__extract_doy
- , subq_17.buy__ds__day
- , subq_17.buy__ds__week
- , subq_17.buy__ds__month
- , subq_17.buy__ds__quarter
- , subq_17.buy__ds__year
- , subq_17.buy__ds__extract_year
- , subq_17.buy__ds__extract_quarter
- , subq_17.buy__ds__extract_month
- , subq_17.buy__ds__extract_day
- , subq_17.buy__ds__extract_dow
- , subq_17.buy__ds__extract_doy
- , subq_17.metric_time__day
- , subq_17.metric_time__week
- , subq_17.metric_time__month
- , subq_17.metric_time__quarter
- , subq_17.metric_time__year
- , subq_17.metric_time__extract_year
- , subq_17.metric_time__extract_quarter
- , subq_17.metric_time__extract_month
- , subq_17.metric_time__extract_day
- , subq_17.metric_time__extract_dow
- , subq_17.metric_time__extract_doy
- , subq_17.user
- , subq_17.session_id
- , subq_17.buy__user
- , subq_17.buy__session_id
- , subq_17.buys
- , subq_17.buyers
- , UUID() AS mf_internal_uuid
- FROM (
- -- Metric Time Dimension 'ds'
+ subq_11.ds__day AS ds__day
+ , subq_11.ds__week AS ds__week
+ , subq_11.ds__month AS ds__month
+ , subq_11.ds__quarter AS ds__quarter
+ , subq_11.ds__year AS ds__year
+ , subq_11.ds__extract_year AS ds__extract_year
+ , subq_11.ds__extract_quarter AS ds__extract_quarter
+ , subq_11.ds__extract_month AS ds__extract_month
+ , subq_11.ds__extract_day AS ds__extract_day
+ , subq_11.ds__extract_dow AS ds__extract_dow
+ , subq_11.ds__extract_doy AS ds__extract_doy
+ , subq_11.visit__ds__day AS visit__ds__day
+ , subq_11.visit__ds__week AS visit__ds__week
+ , subq_11.visit__ds__month AS visit__ds__month
+ , subq_11.visit__ds__quarter AS visit__ds__quarter
+ , subq_11.visit__ds__year AS visit__ds__year
+ , subq_11.visit__ds__extract_year AS visit__ds__extract_year
+ , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
+ , subq_11.visit__ds__extract_month AS visit__ds__extract_month
+ , subq_11.visit__ds__extract_day AS visit__ds__extract_day
+ , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
+ , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
+ , subq_11.metric_time__day AS metric_time__day
+ , subq_11.metric_time__week AS metric_time__week
+ , subq_11.metric_time__month AS metric_time__month
+ , subq_11.metric_time__quarter AS metric_time__quarter
+ , subq_11.metric_time__year AS metric_time__year
+ , subq_11.metric_time__extract_year AS metric_time__extract_year
+ , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_11.metric_time__extract_month AS metric_time__extract_month
+ , subq_11.metric_time__extract_day AS metric_time__extract_day
+ , subq_11.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_11.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_11.user AS user
+ , subq_11.session AS session
+ , subq_11.visit__user AS visit__user
+ , subq_11.visit__session AS visit__session
+ , subq_11.referrer_id AS referrer_id
+ , subq_11.visit__referrer_id AS visit__referrer_id
+ , subq_13.home_state_latest AS user__home_state_latest
+ , subq_11.visits AS visits
+ , subq_11.visitors AS visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.visit__ds__day
+ , subq_10.visit__ds__week
+ , subq_10.visit__ds__month
+ , subq_10.visit__ds__quarter
+ , subq_10.visit__ds__year
+ , subq_10.visit__ds__extract_year
+ , subq_10.visit__ds__extract_quarter
+ , subq_10.visit__ds__extract_month
+ , subq_10.visit__ds__extract_day
+ , subq_10.visit__ds__extract_dow
+ , subq_10.visit__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session
+ , subq_10.visit__user
+ , subq_10.visit__session
+ , subq_10.referrer_id
+ , subq_10.visit__referrer_id
+ , subq_10.visits
+ , subq_10.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_10
+ ) subq_11
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_12.user
+ , subq_12.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_12
+ ) subq_13
+ ON
+ subq_11.user = subq_13.user
+ ) subq_14
+ WHERE visit__referrer_id = '123456'
+ ) subq_15
+ ) subq_16
+ INNER JOIN (
+ -- Add column with generated UUID
SELECT
- subq_16.ds__day
- , subq_16.ds__week
- , subq_16.ds__month
- , subq_16.ds__quarter
- , subq_16.ds__year
- , subq_16.ds__extract_year
- , subq_16.ds__extract_quarter
- , subq_16.ds__extract_month
- , subq_16.ds__extract_day
- , subq_16.ds__extract_dow
- , subq_16.ds__extract_doy
- , subq_16.buy__ds__day
- , subq_16.buy__ds__week
- , subq_16.buy__ds__month
- , subq_16.buy__ds__quarter
- , subq_16.buy__ds__year
- , subq_16.buy__ds__extract_year
- , subq_16.buy__ds__extract_quarter
- , subq_16.buy__ds__extract_month
- , subq_16.buy__ds__extract_day
- , subq_16.buy__ds__extract_dow
- , subq_16.buy__ds__extract_doy
- , subq_16.ds__day AS metric_time__day
- , subq_16.ds__week AS metric_time__week
- , subq_16.ds__month AS metric_time__month
- , subq_16.ds__quarter AS metric_time__quarter
- , subq_16.ds__year AS metric_time__year
- , subq_16.ds__extract_year AS metric_time__extract_year
- , subq_16.ds__extract_quarter AS metric_time__extract_quarter
- , subq_16.ds__extract_month AS metric_time__extract_month
- , subq_16.ds__extract_day AS metric_time__extract_day
- , subq_16.ds__extract_dow AS metric_time__extract_dow
- , subq_16.ds__extract_doy AS metric_time__extract_doy
- , subq_16.user
- , subq_16.session_id
- , subq_16.buy__user
- , subq_16.buy__session_id
- , subq_16.buys
- , subq_16.buyers
+ subq_18.ds__day
+ , subq_18.ds__week
+ , subq_18.ds__month
+ , subq_18.ds__quarter
+ , subq_18.ds__year
+ , subq_18.ds__extract_year
+ , subq_18.ds__extract_quarter
+ , subq_18.ds__extract_month
+ , subq_18.ds__extract_day
+ , subq_18.ds__extract_dow
+ , subq_18.ds__extract_doy
+ , subq_18.buy__ds__day
+ , subq_18.buy__ds__week
+ , subq_18.buy__ds__month
+ , subq_18.buy__ds__quarter
+ , subq_18.buy__ds__year
+ , subq_18.buy__ds__extract_year
+ , subq_18.buy__ds__extract_quarter
+ , subq_18.buy__ds__extract_month
+ , subq_18.buy__ds__extract_day
+ , subq_18.buy__ds__extract_dow
+ , subq_18.buy__ds__extract_doy
+ , subq_18.metric_time__day
+ , subq_18.metric_time__week
+ , subq_18.metric_time__month
+ , subq_18.metric_time__quarter
+ , subq_18.metric_time__year
+ , subq_18.metric_time__extract_year
+ , subq_18.metric_time__extract_quarter
+ , subq_18.metric_time__extract_month
+ , subq_18.metric_time__extract_day
+ , subq_18.metric_time__extract_dow
+ , subq_18.metric_time__extract_doy
+ , subq_18.user
+ , subq_18.session_id
+ , subq_18.buy__user
+ , subq_18.buy__session_id
+ , subq_18.buys
+ , subq_18.buyers
+ , UUID() AS mf_internal_uuid
FROM (
- -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS buys
- , buys_source_src_28000.user_id AS buyers
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM buys_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
- , buys_source_src_28000.user_id AS user
- , buys_source_src_28000.session_id
- , buys_source_src_28000.user_id AS buy__user
- , buys_source_src_28000.session_id AS buy__session_id
- FROM ***************************.fct_buys buys_source_src_28000
- ) subq_16
- ) subq_17
- ) subq_18
- ON
- (
- subq_15.user = subq_18.user
- ) AND (
+ subq_17.ds__day
+ , subq_17.ds__week
+ , subq_17.ds__month
+ , subq_17.ds__quarter
+ , subq_17.ds__year
+ , subq_17.ds__extract_year
+ , subq_17.ds__extract_quarter
+ , subq_17.ds__extract_month
+ , subq_17.ds__extract_day
+ , subq_17.ds__extract_dow
+ , subq_17.ds__extract_doy
+ , subq_17.buy__ds__day
+ , subq_17.buy__ds__week
+ , subq_17.buy__ds__month
+ , subq_17.buy__ds__quarter
+ , subq_17.buy__ds__year
+ , subq_17.buy__ds__extract_year
+ , subq_17.buy__ds__extract_quarter
+ , subq_17.buy__ds__extract_month
+ , subq_17.buy__ds__extract_day
+ , subq_17.buy__ds__extract_dow
+ , subq_17.buy__ds__extract_doy
+ , subq_17.ds__day AS metric_time__day
+ , subq_17.ds__week AS metric_time__week
+ , subq_17.ds__month AS metric_time__month
+ , subq_17.ds__quarter AS metric_time__quarter
+ , subq_17.ds__year AS metric_time__year
+ , subq_17.ds__extract_year AS metric_time__extract_year
+ , subq_17.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_17.ds__extract_month AS metric_time__extract_month
+ , subq_17.ds__extract_day AS metric_time__extract_day
+ , subq_17.ds__extract_dow AS metric_time__extract_dow
+ , subq_17.ds__extract_doy AS metric_time__extract_doy
+ , subq_17.user
+ , subq_17.session_id
+ , subq_17.buy__user
+ , subq_17.buy__session_id
+ , subq_17.buys
+ , subq_17.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM buys_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_17
+ ) subq_18
+ ) subq_19
+ ON
(
- subq_15.ds__day <= subq_18.ds__day
+ subq_16.user = subq_19.user
) AND (
- subq_15.ds__day > DATEADD(day, -7, subq_18.ds__day)
+ (
+ subq_16.ds__day <= subq_19.ds__day
+ ) AND (
+ subq_16.ds__day > DATEADD(day, -7, subq_19.ds__day)
+ )
)
- )
- ) subq_19
- ) subq_20
- ) subq_21
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
- SELECT
- subq_22.user
- , subq_22.home_state_latest
- FROM (
- -- Read Elements From Semantic Model 'users_latest'
- SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_20
+ ) subq_21
) subq_22
- ) subq_23
- ON
- subq_21.user = subq_23.user
- ) subq_24
- ) subq_25
- GROUP BY
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- ) subq_26
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_23.user
+ , subq_23.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_23
+ ) subq_24
+ ON
+ subq_22.user = subq_24.user
+ ) subq_25
+ ) subq_26
+ GROUP BY
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ ) subq_27
+ ) subq_28
ON
(
- subq_9.user__home_state_latest = subq_26.user__home_state_latest
+ subq_9.user__home_state_latest = subq_28.user__home_state_latest
) AND (
- subq_9.metric_time__day = subq_26.metric_time__day
+ subq_9.metric_time__day = subq_28.metric_time__day
)
GROUP BY
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day)
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest)
-) subq_27
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day)
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest)
+) subq_29
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_query_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_query_filters__plan0_optimized.sql
index fc20b83581..cacbaebc53 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_query_filters__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_query_filters__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day) AS metric_time__day
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest) AS user__home_state_latest
- , MAX(subq_37.visits) AS visits
- , MAX(subq_54.buys) AS buys
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day) AS metric_time__day
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest) AS user__home_state_latest
+ , MAX(subq_39.visits) AS visits
+ , MAX(subq_58.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'metric_time__day']
@@ -22,10 +22,10 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_30.metric_time__day AS metric_time__day
- , subq_30.visit__referrer_id AS visit__referrer_id
+ subq_32.metric_time__day AS metric_time__day
+ , subq_32.visit__referrer_id AS visit__referrer_id
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_30.visits AS visits
+ , subq_32.visits AS visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
@@ -36,104 +36,116 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_30
+ ) subq_32
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_30.user = users_latest_src_28000.user_id
- ) subq_34
+ subq_32.user = users_latest_src_28000.user_id
+ ) subq_36
WHERE visit__referrer_id = '123456'
GROUP BY
metric_time__day
, user__home_state_latest
- ) subq_37
+ ) subq_39
FULL OUTER JOIN (
-- Join Standard Outputs
-- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
-- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_47.metric_time__day AS metric_time__day
+ subq_50.metric_time__day AS metric_time__day
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , SUM(subq_47.buys) AS buys
+ , SUM(subq_50.buys) AS buys
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_43.visits) OVER (
+ FIRST_VALUE(subq_46.visits) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_43.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_46.visit__referrer_id) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_43.user__home_state_latest) OVER (
+ , FIRST_VALUE(subq_46.user__home_state_latest) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user__home_state_latest
- , FIRST_VALUE(subq_43.ds__day) OVER (
+ , FIRST_VALUE(subq_46.ds__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_43.metric_time__day) OVER (
+ , FIRST_VALUE(subq_46.metric_time__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_43.user) OVER (
+ , FIRST_VALUE(subq_46.user) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_46.mf_internal_uuid AS mf_internal_uuid
- , subq_46.buys AS buys
+ , subq_49.mf_internal_uuid AS mf_internal_uuid
+ , subq_49.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_39.ds__day AS ds__day
- , subq_39.metric_time__day AS metric_time__day
- , subq_39.user AS user
- , subq_39.visit__referrer_id AS visit__referrer_id
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_39.visits AS visits
+ ds__day
+ , metric_time__day
+ , subq_44.user
+ , visit__referrer_id
+ , user__home_state_latest
+ , visits
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , DATE_TRUNC('day', ds) 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_39
- LEFT OUTER JOIN
- ***************************.dim_users_latest users_latest_src_28000
- ON
- subq_39.user = users_latest_src_28000.user_id
- ) subq_43
+ subq_41.ds__day AS ds__day
+ , subq_41.metric_time__day AS metric_time__day
+ , subq_41.user AS user
+ , subq_41.visit__referrer_id AS visit__referrer_id
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , subq_41.visits AS visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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_41
+ LEFT OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_28000
+ ON
+ subq_41.user = users_latest_src_28000.user_id
+ ) subq_44
+ WHERE visit__referrer_id = '123456'
+ ) subq_46
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -144,33 +156,33 @@ FROM (
, 1 AS buys
, UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_46
+ ) subq_49
ON
(
- subq_43.user = subq_46.user
+ subq_46.user = subq_49.user
) AND (
(
- subq_43.ds__day <= subq_46.ds__day
+ subq_46.ds__day <= subq_49.ds__day
) AND (
- subq_43.ds__day > DATEADD(day, -7, subq_46.ds__day)
+ subq_46.ds__day > DATEADD(day, -7, subq_49.ds__day)
)
)
- ) subq_47
+ ) subq_50
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_47.user = users_latest_src_28000.user_id
+ subq_50.user = users_latest_src_28000.user_id
GROUP BY
- subq_47.metric_time__day
+ subq_50.metric_time__day
, users_latest_src_28000.home_state_latest
- ) subq_54
+ ) subq_58
ON
(
- subq_37.user__home_state_latest = subq_54.user__home_state_latest
+ subq_39.user__home_state_latest = subq_58.user__home_state_latest
) AND (
- subq_37.metric_time__day = subq_54.metric_time__day
+ subq_39.metric_time__day = subq_58.metric_time__day
)
GROUP BY
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day)
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest)
-) subq_55
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day)
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest)
+) subq_59
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0.sql
index b1a1412d9d..09634af5ca 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_27.metric_time__day
- , subq_27.user__home_state_latest
- , CAST(subq_27.buys AS DOUBLE) / CAST(NULLIF(subq_27.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_29.metric_time__day
+ , subq_29.user__home_state_latest
+ , CAST(subq_29.buys AS DOUBLE) / CAST(NULLIF(subq_29.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day) AS metric_time__day
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest) AS user__home_state_latest
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day) AS metric_time__day
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest) AS user__home_state_latest
, MAX(subq_9.visits) AS visits
- , MAX(subq_26.buys) AS buys
+ , MAX(subq_28.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -180,453 +180,507 @@ FROM (
, subq_8.user__home_state_latest
) subq_9
FULL OUTER JOIN (
- -- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- , SUM(subq_25.buys) AS buys
+ subq_27.metric_time__day
+ , subq_27.user__home_state_latest
+ , subq_27.buys
FROM (
- -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
+ -- Aggregate Measures
SELECT
- subq_24.metric_time__day
- , subq_24.user__home_state_latest
- , subq_24.buys
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ , SUM(subq_26.buys) AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_21.metric_time__day AS metric_time__day
- , subq_21.user AS user
- , subq_21.visit__referrer_id AS visit__referrer_id
- , subq_23.home_state_latest AS user__home_state_latest
- , subq_21.buys AS buys
+ subq_25.metric_time__day
+ , subq_25.user__home_state_latest
+ , subq_25.buys
FROM (
- -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
+ -- Join Standard Outputs
SELECT
- subq_20.metric_time__day
- , subq_20.user
- , subq_20.visit__referrer_id
- , subq_20.buys
+ subq_22.metric_time__day AS metric_time__day
+ , subq_22.user AS user
+ , subq_22.visit__referrer_id AS visit__referrer_id
+ , subq_24.home_state_latest AS user__home_state_latest
+ , subq_22.buys AS buys
FROM (
- -- Find conversions for user within the range of 7 day
+ -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
SELECT
- subq_19.ds__day
- , subq_19.metric_time__day
- , subq_19.user
- , subq_19.visit__referrer_id
- , subq_19.user__home_state_latest
- , subq_19.buys
- , subq_19.visits
+ subq_21.metric_time__day
+ , subq_21.user
+ , subq_21.visit__referrer_id
+ , subq_21.buys
FROM (
- -- Dedupe the fanout with mf_internal_uuid in the conversion data set
- SELECT DISTINCT
- FIRST_VALUE(subq_15.visits) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visits
- , FIRST_VALUE(subq_15.visit__referrer_id) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visit__referrer_id
- , FIRST_VALUE(subq_15.user__home_state_latest) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user__home_state_latest
- , FIRST_VALUE(subq_15.ds__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS ds__day
- , FIRST_VALUE(subq_15.metric_time__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS metric_time__day
- , FIRST_VALUE(subq_15.user) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user
- , subq_18.mf_internal_uuid AS mf_internal_uuid
- , subq_18.buys AS buys
+ -- Find conversions for user within the range of 7 day
+ SELECT
+ subq_20.ds__day
+ , subq_20.metric_time__day
+ , subq_20.user
+ , subq_20.visit__referrer_id
+ , subq_20.user__home_state_latest
+ , subq_20.buys
+ , subq_20.visits
FROM (
- -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
- SELECT
- subq_14.ds__day
- , subq_14.metric_time__day
- , subq_14.user
- , subq_14.visit__referrer_id
- , subq_14.user__home_state_latest
- , subq_14.visits
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_16.visits) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_16.visit__referrer_id) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visit__referrer_id
+ , FIRST_VALUE(subq_16.user__home_state_latest) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user__home_state_latest
+ , FIRST_VALUE(subq_16.ds__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_16.metric_time__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_16.user) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_19.mf_internal_uuid AS mf_internal_uuid
+ , subq_19.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_11.ds__day AS ds__day
- , subq_11.ds__week AS ds__week
- , subq_11.ds__month AS ds__month
- , subq_11.ds__quarter AS ds__quarter
- , subq_11.ds__year AS ds__year
- , subq_11.ds__extract_year AS ds__extract_year
- , subq_11.ds__extract_quarter AS ds__extract_quarter
- , subq_11.ds__extract_month AS ds__extract_month
- , subq_11.ds__extract_day AS ds__extract_day
- , subq_11.ds__extract_dow AS ds__extract_dow
- , subq_11.ds__extract_doy AS ds__extract_doy
- , subq_11.visit__ds__day AS visit__ds__day
- , subq_11.visit__ds__week AS visit__ds__week
- , subq_11.visit__ds__month AS visit__ds__month
- , subq_11.visit__ds__quarter AS visit__ds__quarter
- , subq_11.visit__ds__year AS visit__ds__year
- , subq_11.visit__ds__extract_year AS visit__ds__extract_year
- , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
- , subq_11.visit__ds__extract_month AS visit__ds__extract_month
- , subq_11.visit__ds__extract_day AS visit__ds__extract_day
- , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
- , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
- , subq_11.metric_time__day AS metric_time__day
- , subq_11.metric_time__week AS metric_time__week
- , subq_11.metric_time__month AS metric_time__month
- , subq_11.metric_time__quarter AS metric_time__quarter
- , subq_11.metric_time__year AS metric_time__year
- , subq_11.metric_time__extract_year AS metric_time__extract_year
- , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
- , subq_11.metric_time__extract_month AS metric_time__extract_month
- , subq_11.metric_time__extract_day AS metric_time__extract_day
- , subq_11.metric_time__extract_dow AS metric_time__extract_dow
- , subq_11.metric_time__extract_doy AS metric_time__extract_doy
- , subq_11.user AS user
- , subq_11.session AS session
- , subq_11.visit__user AS visit__user
- , subq_11.visit__session AS visit__session
- , subq_11.referrer_id AS referrer_id
- , subq_11.visit__referrer_id AS visit__referrer_id
- , subq_13.home_state_latest AS user__home_state_latest
- , subq_11.visits AS visits
- , subq_11.visitors AS visitors
+ subq_15.ds__day
+ , subq_15.metric_time__day
+ , subq_15.user
+ , subq_15.visit__referrer_id
+ , subq_15.user__home_state_latest
+ , subq_15.visits
FROM (
- -- Metric Time Dimension 'ds'
- SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.visit__ds__day
- , subq_10.visit__ds__week
- , subq_10.visit__ds__month
- , subq_10.visit__ds__quarter
- , subq_10.visit__ds__year
- , subq_10.visit__ds__extract_year
- , subq_10.visit__ds__extract_quarter
- , subq_10.visit__ds__extract_month
- , subq_10.visit__ds__extract_day
- , subq_10.visit__ds__extract_dow
- , subq_10.visit__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session
- , subq_10.visit__user
- , subq_10.visit__session
- , subq_10.referrer_id
- , subq_10.visit__referrer_id
- , subq_10.visits
- , subq_10.visitors
- FROM (
- -- Read Elements From Semantic Model 'visits_source'
- SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_10
- ) subq_11
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
+ -- Constrain Output with WHERE
SELECT
- subq_12.user
- , subq_12.home_state_latest
+ subq_14.ds__day
+ , subq_14.ds__week
+ , subq_14.ds__month
+ , subq_14.ds__quarter
+ , subq_14.ds__year
+ , subq_14.ds__extract_year
+ , subq_14.ds__extract_quarter
+ , subq_14.ds__extract_month
+ , subq_14.ds__extract_day
+ , subq_14.ds__extract_dow
+ , subq_14.ds__extract_doy
+ , subq_14.visit__ds__day
+ , subq_14.visit__ds__week
+ , subq_14.visit__ds__month
+ , subq_14.visit__ds__quarter
+ , subq_14.visit__ds__year
+ , subq_14.visit__ds__extract_year
+ , subq_14.visit__ds__extract_quarter
+ , subq_14.visit__ds__extract_month
+ , subq_14.visit__ds__extract_day
+ , subq_14.visit__ds__extract_dow
+ , subq_14.visit__ds__extract_doy
+ , subq_14.metric_time__day
+ , subq_14.metric_time__week
+ , subq_14.metric_time__month
+ , subq_14.metric_time__quarter
+ , subq_14.metric_time__year
+ , subq_14.metric_time__extract_year
+ , subq_14.metric_time__extract_quarter
+ , subq_14.metric_time__extract_month
+ , subq_14.metric_time__extract_day
+ , subq_14.metric_time__extract_dow
+ , subq_14.metric_time__extract_doy
+ , subq_14.user
+ , subq_14.session
+ , subq_14.visit__user
+ , subq_14.visit__session
+ , subq_14.referrer_id
+ , subq_14.visit__referrer_id
+ , subq_14.user__home_state_latest
+ , subq_14.visits
+ , subq_14.visitors
FROM (
- -- Read Elements From Semantic Model 'users_latest'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
- ) subq_12
- ) subq_13
- ON
- subq_11.user = subq_13.user
- ) subq_14
- ) subq_15
- INNER JOIN (
- -- Add column with generated UUID
- SELECT
- subq_17.ds__day
- , subq_17.ds__week
- , subq_17.ds__month
- , subq_17.ds__quarter
- , subq_17.ds__year
- , subq_17.ds__extract_year
- , subq_17.ds__extract_quarter
- , subq_17.ds__extract_month
- , subq_17.ds__extract_day
- , subq_17.ds__extract_dow
- , subq_17.ds__extract_doy
- , subq_17.buy__ds__day
- , subq_17.buy__ds__week
- , subq_17.buy__ds__month
- , subq_17.buy__ds__quarter
- , subq_17.buy__ds__year
- , subq_17.buy__ds__extract_year
- , subq_17.buy__ds__extract_quarter
- , subq_17.buy__ds__extract_month
- , subq_17.buy__ds__extract_day
- , subq_17.buy__ds__extract_dow
- , subq_17.buy__ds__extract_doy
- , subq_17.metric_time__day
- , subq_17.metric_time__week
- , subq_17.metric_time__month
- , subq_17.metric_time__quarter
- , subq_17.metric_time__year
- , subq_17.metric_time__extract_year
- , subq_17.metric_time__extract_quarter
- , subq_17.metric_time__extract_month
- , subq_17.metric_time__extract_day
- , subq_17.metric_time__extract_dow
- , subq_17.metric_time__extract_doy
- , subq_17.user
- , subq_17.session_id
- , subq_17.buy__user
- , subq_17.buy__session_id
- , subq_17.buys
- , subq_17.buyers
- , GEN_RANDOM_UUID() AS mf_internal_uuid
- FROM (
- -- Metric Time Dimension 'ds'
+ subq_11.ds__day AS ds__day
+ , subq_11.ds__week AS ds__week
+ , subq_11.ds__month AS ds__month
+ , subq_11.ds__quarter AS ds__quarter
+ , subq_11.ds__year AS ds__year
+ , subq_11.ds__extract_year AS ds__extract_year
+ , subq_11.ds__extract_quarter AS ds__extract_quarter
+ , subq_11.ds__extract_month AS ds__extract_month
+ , subq_11.ds__extract_day AS ds__extract_day
+ , subq_11.ds__extract_dow AS ds__extract_dow
+ , subq_11.ds__extract_doy AS ds__extract_doy
+ , subq_11.visit__ds__day AS visit__ds__day
+ , subq_11.visit__ds__week AS visit__ds__week
+ , subq_11.visit__ds__month AS visit__ds__month
+ , subq_11.visit__ds__quarter AS visit__ds__quarter
+ , subq_11.visit__ds__year AS visit__ds__year
+ , subq_11.visit__ds__extract_year AS visit__ds__extract_year
+ , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
+ , subq_11.visit__ds__extract_month AS visit__ds__extract_month
+ , subq_11.visit__ds__extract_day AS visit__ds__extract_day
+ , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
+ , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
+ , subq_11.metric_time__day AS metric_time__day
+ , subq_11.metric_time__week AS metric_time__week
+ , subq_11.metric_time__month AS metric_time__month
+ , subq_11.metric_time__quarter AS metric_time__quarter
+ , subq_11.metric_time__year AS metric_time__year
+ , subq_11.metric_time__extract_year AS metric_time__extract_year
+ , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_11.metric_time__extract_month AS metric_time__extract_month
+ , subq_11.metric_time__extract_day AS metric_time__extract_day
+ , subq_11.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_11.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_11.user AS user
+ , subq_11.session AS session
+ , subq_11.visit__user AS visit__user
+ , subq_11.visit__session AS visit__session
+ , subq_11.referrer_id AS referrer_id
+ , subq_11.visit__referrer_id AS visit__referrer_id
+ , subq_13.home_state_latest AS user__home_state_latest
+ , subq_11.visits AS visits
+ , subq_11.visitors AS visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.visit__ds__day
+ , subq_10.visit__ds__week
+ , subq_10.visit__ds__month
+ , subq_10.visit__ds__quarter
+ , subq_10.visit__ds__year
+ , subq_10.visit__ds__extract_year
+ , subq_10.visit__ds__extract_quarter
+ , subq_10.visit__ds__extract_month
+ , subq_10.visit__ds__extract_day
+ , subq_10.visit__ds__extract_dow
+ , subq_10.visit__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session
+ , subq_10.visit__user
+ , subq_10.visit__session
+ , subq_10.referrer_id
+ , subq_10.visit__referrer_id
+ , subq_10.visits
+ , subq_10.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_10
+ ) subq_11
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_12.user
+ , subq_12.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_12
+ ) subq_13
+ ON
+ subq_11.user = subq_13.user
+ ) subq_14
+ WHERE visit__referrer_id = '123456'
+ ) subq_15
+ ) subq_16
+ INNER JOIN (
+ -- Add column with generated UUID
SELECT
- subq_16.ds__day
- , subq_16.ds__week
- , subq_16.ds__month
- , subq_16.ds__quarter
- , subq_16.ds__year
- , subq_16.ds__extract_year
- , subq_16.ds__extract_quarter
- , subq_16.ds__extract_month
- , subq_16.ds__extract_day
- , subq_16.ds__extract_dow
- , subq_16.ds__extract_doy
- , subq_16.buy__ds__day
- , subq_16.buy__ds__week
- , subq_16.buy__ds__month
- , subq_16.buy__ds__quarter
- , subq_16.buy__ds__year
- , subq_16.buy__ds__extract_year
- , subq_16.buy__ds__extract_quarter
- , subq_16.buy__ds__extract_month
- , subq_16.buy__ds__extract_day
- , subq_16.buy__ds__extract_dow
- , subq_16.buy__ds__extract_doy
- , subq_16.ds__day AS metric_time__day
- , subq_16.ds__week AS metric_time__week
- , subq_16.ds__month AS metric_time__month
- , subq_16.ds__quarter AS metric_time__quarter
- , subq_16.ds__year AS metric_time__year
- , subq_16.ds__extract_year AS metric_time__extract_year
- , subq_16.ds__extract_quarter AS metric_time__extract_quarter
- , subq_16.ds__extract_month AS metric_time__extract_month
- , subq_16.ds__extract_day AS metric_time__extract_day
- , subq_16.ds__extract_dow AS metric_time__extract_dow
- , subq_16.ds__extract_doy AS metric_time__extract_doy
- , subq_16.user
- , subq_16.session_id
- , subq_16.buy__user
- , subq_16.buy__session_id
- , subq_16.buys
- , subq_16.buyers
+ subq_18.ds__day
+ , subq_18.ds__week
+ , subq_18.ds__month
+ , subq_18.ds__quarter
+ , subq_18.ds__year
+ , subq_18.ds__extract_year
+ , subq_18.ds__extract_quarter
+ , subq_18.ds__extract_month
+ , subq_18.ds__extract_day
+ , subq_18.ds__extract_dow
+ , subq_18.ds__extract_doy
+ , subq_18.buy__ds__day
+ , subq_18.buy__ds__week
+ , subq_18.buy__ds__month
+ , subq_18.buy__ds__quarter
+ , subq_18.buy__ds__year
+ , subq_18.buy__ds__extract_year
+ , subq_18.buy__ds__extract_quarter
+ , subq_18.buy__ds__extract_month
+ , subq_18.buy__ds__extract_day
+ , subq_18.buy__ds__extract_dow
+ , subq_18.buy__ds__extract_doy
+ , subq_18.metric_time__day
+ , subq_18.metric_time__week
+ , subq_18.metric_time__month
+ , subq_18.metric_time__quarter
+ , subq_18.metric_time__year
+ , subq_18.metric_time__extract_year
+ , subq_18.metric_time__extract_quarter
+ , subq_18.metric_time__extract_month
+ , subq_18.metric_time__extract_day
+ , subq_18.metric_time__extract_dow
+ , subq_18.metric_time__extract_doy
+ , subq_18.user
+ , subq_18.session_id
+ , subq_18.buy__user
+ , subq_18.buy__session_id
+ , subq_18.buys
+ , subq_18.buyers
+ , GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
- -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS buys
- , buys_source_src_28000.user_id AS buyers
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
- , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
- , buys_source_src_28000.user_id AS user
- , buys_source_src_28000.session_id
- , buys_source_src_28000.user_id AS buy__user
- , buys_source_src_28000.session_id AS buy__session_id
- FROM ***************************.fct_buys buys_source_src_28000
- ) subq_16
- ) subq_17
- ) subq_18
- ON
- (
- subq_15.user = subq_18.user
- ) AND (
+ subq_17.ds__day
+ , subq_17.ds__week
+ , subq_17.ds__month
+ , subq_17.ds__quarter
+ , subq_17.ds__year
+ , subq_17.ds__extract_year
+ , subq_17.ds__extract_quarter
+ , subq_17.ds__extract_month
+ , subq_17.ds__extract_day
+ , subq_17.ds__extract_dow
+ , subq_17.ds__extract_doy
+ , subq_17.buy__ds__day
+ , subq_17.buy__ds__week
+ , subq_17.buy__ds__month
+ , subq_17.buy__ds__quarter
+ , subq_17.buy__ds__year
+ , subq_17.buy__ds__extract_year
+ , subq_17.buy__ds__extract_quarter
+ , subq_17.buy__ds__extract_month
+ , subq_17.buy__ds__extract_day
+ , subq_17.buy__ds__extract_dow
+ , subq_17.buy__ds__extract_doy
+ , subq_17.ds__day AS metric_time__day
+ , subq_17.ds__week AS metric_time__week
+ , subq_17.ds__month AS metric_time__month
+ , subq_17.ds__quarter AS metric_time__quarter
+ , subq_17.ds__year AS metric_time__year
+ , subq_17.ds__extract_year AS metric_time__extract_year
+ , subq_17.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_17.ds__extract_month AS metric_time__extract_month
+ , subq_17.ds__extract_day AS metric_time__extract_day
+ , subq_17.ds__extract_dow AS metric_time__extract_dow
+ , subq_17.ds__extract_doy AS metric_time__extract_doy
+ , subq_17.user
+ , subq_17.session_id
+ , subq_17.buy__user
+ , subq_17.buy__session_id
+ , subq_17.buys
+ , subq_17.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_17
+ ) subq_18
+ ) subq_19
+ ON
(
- subq_15.ds__day <= subq_18.ds__day
+ subq_16.user = subq_19.user
) AND (
- subq_15.ds__day > subq_18.ds__day - INTERVAL 7 day
+ (
+ subq_16.ds__day <= subq_19.ds__day
+ ) AND (
+ subq_16.ds__day > subq_19.ds__day - INTERVAL 7 day
+ )
)
- )
- ) subq_19
- ) subq_20
- ) subq_21
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
- SELECT
- subq_22.user
- , subq_22.home_state_latest
- FROM (
- -- Read Elements From Semantic Model 'users_latest'
- SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_20
+ ) subq_21
) subq_22
- ) subq_23
- ON
- subq_21.user = subq_23.user
- ) subq_24
- ) subq_25
- GROUP BY
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- ) subq_26
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_23.user
+ , subq_23.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_23
+ ) subq_24
+ ON
+ subq_22.user = subq_24.user
+ ) subq_25
+ ) subq_26
+ GROUP BY
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ ) subq_27
+ ) subq_28
ON
(
- subq_9.user__home_state_latest = subq_26.user__home_state_latest
+ subq_9.user__home_state_latest = subq_28.user__home_state_latest
) AND (
- subq_9.metric_time__day = subq_26.metric_time__day
+ subq_9.metric_time__day = subq_28.metric_time__day
)
GROUP BY
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day)
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest)
-) subq_27
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day)
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest)
+) subq_29
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0_optimized.sql
index 61e0c5aeec..efe71e978d 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day) AS metric_time__day
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest) AS user__home_state_latest
- , MAX(subq_37.visits) AS visits
- , MAX(subq_54.buys) AS buys
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day) AS metric_time__day
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest) AS user__home_state_latest
+ , MAX(subq_39.visits) AS visits
+ , MAX(subq_58.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'metric_time__day']
@@ -22,10 +22,10 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_30.metric_time__day AS metric_time__day
- , subq_30.visit__referrer_id AS visit__referrer_id
+ subq_32.metric_time__day AS metric_time__day
+ , subq_32.visit__referrer_id AS visit__referrer_id
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_30.visits AS visits
+ , subq_32.visits AS visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
@@ -36,104 +36,116 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_30
+ ) subq_32
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_30.user = users_latest_src_28000.user_id
- ) subq_34
+ subq_32.user = users_latest_src_28000.user_id
+ ) subq_36
WHERE visit__referrer_id = '123456'
GROUP BY
metric_time__day
, user__home_state_latest
- ) subq_37
+ ) subq_39
FULL OUTER JOIN (
-- Join Standard Outputs
-- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
-- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_47.metric_time__day AS metric_time__day
+ subq_50.metric_time__day AS metric_time__day
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , SUM(subq_47.buys) AS buys
+ , SUM(subq_50.buys) AS buys
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_43.visits) OVER (
+ FIRST_VALUE(subq_46.visits) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_43.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_46.visit__referrer_id) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_43.user__home_state_latest) OVER (
+ , FIRST_VALUE(subq_46.user__home_state_latest) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user__home_state_latest
- , FIRST_VALUE(subq_43.ds__day) OVER (
+ , FIRST_VALUE(subq_46.ds__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_43.metric_time__day) OVER (
+ , FIRST_VALUE(subq_46.metric_time__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_43.user) OVER (
+ , FIRST_VALUE(subq_46.user) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_46.mf_internal_uuid AS mf_internal_uuid
- , subq_46.buys AS buys
+ , subq_49.mf_internal_uuid AS mf_internal_uuid
+ , subq_49.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_39.ds__day AS ds__day
- , subq_39.metric_time__day AS metric_time__day
- , subq_39.user AS user
- , subq_39.visit__referrer_id AS visit__referrer_id
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_39.visits AS visits
+ ds__day
+ , metric_time__day
+ , subq_44.user
+ , visit__referrer_id
+ , user__home_state_latest
+ , visits
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , DATE_TRUNC('day', ds) 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_39
- LEFT OUTER JOIN
- ***************************.dim_users_latest users_latest_src_28000
- ON
- subq_39.user = users_latest_src_28000.user_id
- ) subq_43
+ subq_41.ds__day AS ds__day
+ , subq_41.metric_time__day AS metric_time__day
+ , subq_41.user AS user
+ , subq_41.visit__referrer_id AS visit__referrer_id
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , subq_41.visits AS visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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_41
+ LEFT OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_28000
+ ON
+ subq_41.user = users_latest_src_28000.user_id
+ ) subq_44
+ WHERE visit__referrer_id = '123456'
+ ) subq_46
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -144,33 +156,33 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_46
+ ) subq_49
ON
(
- subq_43.user = subq_46.user
+ subq_46.user = subq_49.user
) AND (
(
- subq_43.ds__day <= subq_46.ds__day
+ subq_46.ds__day <= subq_49.ds__day
) AND (
- subq_43.ds__day > subq_46.ds__day - INTERVAL 7 day
+ subq_46.ds__day > subq_49.ds__day - INTERVAL 7 day
)
)
- ) subq_47
+ ) subq_50
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_47.user = users_latest_src_28000.user_id
+ subq_50.user = users_latest_src_28000.user_id
GROUP BY
- subq_47.metric_time__day
+ subq_50.metric_time__day
, users_latest_src_28000.home_state_latest
- ) subq_54
+ ) subq_58
ON
(
- subq_37.user__home_state_latest = subq_54.user__home_state_latest
+ subq_39.user__home_state_latest = subq_58.user__home_state_latest
) AND (
- subq_37.metric_time__day = subq_54.metric_time__day
+ subq_39.metric_time__day = subq_58.metric_time__day
)
GROUP BY
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day)
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest)
-) subq_55
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day)
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest)
+) subq_59
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_query_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_query_filters__plan0.sql
index 6204ac7c34..519c3b259f 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_query_filters__plan0.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_query_filters__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_27.metric_time__day
- , subq_27.user__home_state_latest
- , CAST(subq_27.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_27.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
+ subq_29.metric_time__day
+ , subq_29.user__home_state_latest
+ , CAST(subq_29.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_29.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day) AS metric_time__day
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest) AS user__home_state_latest
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day) AS metric_time__day
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest) AS user__home_state_latest
, MAX(subq_9.visits) AS visits
- , MAX(subq_26.buys) AS buys
+ , MAX(subq_28.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -180,453 +180,507 @@ FROM (
, subq_8.user__home_state_latest
) subq_9
FULL OUTER JOIN (
- -- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- , SUM(subq_25.buys) AS buys
+ subq_27.metric_time__day
+ , subq_27.user__home_state_latest
+ , subq_27.buys
FROM (
- -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
+ -- Aggregate Measures
SELECT
- subq_24.metric_time__day
- , subq_24.user__home_state_latest
- , subq_24.buys
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ , SUM(subq_26.buys) AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_21.metric_time__day AS metric_time__day
- , subq_21.user AS user
- , subq_21.visit__referrer_id AS visit__referrer_id
- , subq_23.home_state_latest AS user__home_state_latest
- , subq_21.buys AS buys
+ subq_25.metric_time__day
+ , subq_25.user__home_state_latest
+ , subq_25.buys
FROM (
- -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
+ -- Join Standard Outputs
SELECT
- subq_20.metric_time__day
- , subq_20.user
- , subq_20.visit__referrer_id
- , subq_20.buys
+ subq_22.metric_time__day AS metric_time__day
+ , subq_22.user AS user
+ , subq_22.visit__referrer_id AS visit__referrer_id
+ , subq_24.home_state_latest AS user__home_state_latest
+ , subq_22.buys AS buys
FROM (
- -- Find conversions for user within the range of 7 day
+ -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
SELECT
- subq_19.ds__day
- , subq_19.metric_time__day
- , subq_19.user
- , subq_19.visit__referrer_id
- , subq_19.user__home_state_latest
- , subq_19.buys
- , subq_19.visits
+ subq_21.metric_time__day
+ , subq_21.user
+ , subq_21.visit__referrer_id
+ , subq_21.buys
FROM (
- -- Dedupe the fanout with mf_internal_uuid in the conversion data set
- SELECT DISTINCT
- FIRST_VALUE(subq_15.visits) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visits
- , FIRST_VALUE(subq_15.visit__referrer_id) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visit__referrer_id
- , FIRST_VALUE(subq_15.user__home_state_latest) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user__home_state_latest
- , FIRST_VALUE(subq_15.ds__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS ds__day
- , FIRST_VALUE(subq_15.metric_time__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS metric_time__day
- , FIRST_VALUE(subq_15.user) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user
- , subq_18.mf_internal_uuid AS mf_internal_uuid
- , subq_18.buys AS buys
+ -- Find conversions for user within the range of 7 day
+ SELECT
+ subq_20.ds__day
+ , subq_20.metric_time__day
+ , subq_20.user
+ , subq_20.visit__referrer_id
+ , subq_20.user__home_state_latest
+ , subq_20.buys
+ , subq_20.visits
FROM (
- -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
- SELECT
- subq_14.ds__day
- , subq_14.metric_time__day
- , subq_14.user
- , subq_14.visit__referrer_id
- , subq_14.user__home_state_latest
- , subq_14.visits
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_16.visits) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_16.visit__referrer_id) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visit__referrer_id
+ , FIRST_VALUE(subq_16.user__home_state_latest) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user__home_state_latest
+ , FIRST_VALUE(subq_16.ds__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_16.metric_time__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_16.user) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_19.mf_internal_uuid AS mf_internal_uuid
+ , subq_19.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_11.ds__day AS ds__day
- , subq_11.ds__week AS ds__week
- , subq_11.ds__month AS ds__month
- , subq_11.ds__quarter AS ds__quarter
- , subq_11.ds__year AS ds__year
- , subq_11.ds__extract_year AS ds__extract_year
- , subq_11.ds__extract_quarter AS ds__extract_quarter
- , subq_11.ds__extract_month AS ds__extract_month
- , subq_11.ds__extract_day AS ds__extract_day
- , subq_11.ds__extract_dow AS ds__extract_dow
- , subq_11.ds__extract_doy AS ds__extract_doy
- , subq_11.visit__ds__day AS visit__ds__day
- , subq_11.visit__ds__week AS visit__ds__week
- , subq_11.visit__ds__month AS visit__ds__month
- , subq_11.visit__ds__quarter AS visit__ds__quarter
- , subq_11.visit__ds__year AS visit__ds__year
- , subq_11.visit__ds__extract_year AS visit__ds__extract_year
- , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
- , subq_11.visit__ds__extract_month AS visit__ds__extract_month
- , subq_11.visit__ds__extract_day AS visit__ds__extract_day
- , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
- , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
- , subq_11.metric_time__day AS metric_time__day
- , subq_11.metric_time__week AS metric_time__week
- , subq_11.metric_time__month AS metric_time__month
- , subq_11.metric_time__quarter AS metric_time__quarter
- , subq_11.metric_time__year AS metric_time__year
- , subq_11.metric_time__extract_year AS metric_time__extract_year
- , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
- , subq_11.metric_time__extract_month AS metric_time__extract_month
- , subq_11.metric_time__extract_day AS metric_time__extract_day
- , subq_11.metric_time__extract_dow AS metric_time__extract_dow
- , subq_11.metric_time__extract_doy AS metric_time__extract_doy
- , subq_11.user AS user
- , subq_11.session AS session
- , subq_11.visit__user AS visit__user
- , subq_11.visit__session AS visit__session
- , subq_11.referrer_id AS referrer_id
- , subq_11.visit__referrer_id AS visit__referrer_id
- , subq_13.home_state_latest AS user__home_state_latest
- , subq_11.visits AS visits
- , subq_11.visitors AS visitors
+ subq_15.ds__day
+ , subq_15.metric_time__day
+ , subq_15.user
+ , subq_15.visit__referrer_id
+ , subq_15.user__home_state_latest
+ , subq_15.visits
FROM (
- -- Metric Time Dimension 'ds'
- SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.visit__ds__day
- , subq_10.visit__ds__week
- , subq_10.visit__ds__month
- , subq_10.visit__ds__quarter
- , subq_10.visit__ds__year
- , subq_10.visit__ds__extract_year
- , subq_10.visit__ds__extract_quarter
- , subq_10.visit__ds__extract_month
- , subq_10.visit__ds__extract_day
- , subq_10.visit__ds__extract_dow
- , subq_10.visit__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session
- , subq_10.visit__user
- , subq_10.visit__session
- , subq_10.referrer_id
- , subq_10.visit__referrer_id
- , subq_10.visits
- , subq_10.visitors
- FROM (
- -- Read Elements From Semantic Model 'visits_source'
- SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_10
- ) subq_11
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
+ -- Constrain Output with WHERE
SELECT
- subq_12.user
- , subq_12.home_state_latest
+ subq_14.ds__day
+ , subq_14.ds__week
+ , subq_14.ds__month
+ , subq_14.ds__quarter
+ , subq_14.ds__year
+ , subq_14.ds__extract_year
+ , subq_14.ds__extract_quarter
+ , subq_14.ds__extract_month
+ , subq_14.ds__extract_day
+ , subq_14.ds__extract_dow
+ , subq_14.ds__extract_doy
+ , subq_14.visit__ds__day
+ , subq_14.visit__ds__week
+ , subq_14.visit__ds__month
+ , subq_14.visit__ds__quarter
+ , subq_14.visit__ds__year
+ , subq_14.visit__ds__extract_year
+ , subq_14.visit__ds__extract_quarter
+ , subq_14.visit__ds__extract_month
+ , subq_14.visit__ds__extract_day
+ , subq_14.visit__ds__extract_dow
+ , subq_14.visit__ds__extract_doy
+ , subq_14.metric_time__day
+ , subq_14.metric_time__week
+ , subq_14.metric_time__month
+ , subq_14.metric_time__quarter
+ , subq_14.metric_time__year
+ , subq_14.metric_time__extract_year
+ , subq_14.metric_time__extract_quarter
+ , subq_14.metric_time__extract_month
+ , subq_14.metric_time__extract_day
+ , subq_14.metric_time__extract_dow
+ , subq_14.metric_time__extract_doy
+ , subq_14.user
+ , subq_14.session
+ , subq_14.visit__user
+ , subq_14.visit__session
+ , subq_14.referrer_id
+ , subq_14.visit__referrer_id
+ , subq_14.user__home_state_latest
+ , subq_14.visits
+ , subq_14.visitors
FROM (
- -- Read Elements From Semantic Model 'users_latest'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
- ) subq_12
- ) subq_13
- ON
- subq_11.user = subq_13.user
- ) subq_14
- ) subq_15
- INNER JOIN (
- -- Add column with generated UUID
- SELECT
- subq_17.ds__day
- , subq_17.ds__week
- , subq_17.ds__month
- , subq_17.ds__quarter
- , subq_17.ds__year
- , subq_17.ds__extract_year
- , subq_17.ds__extract_quarter
- , subq_17.ds__extract_month
- , subq_17.ds__extract_day
- , subq_17.ds__extract_dow
- , subq_17.ds__extract_doy
- , subq_17.buy__ds__day
- , subq_17.buy__ds__week
- , subq_17.buy__ds__month
- , subq_17.buy__ds__quarter
- , subq_17.buy__ds__year
- , subq_17.buy__ds__extract_year
- , subq_17.buy__ds__extract_quarter
- , subq_17.buy__ds__extract_month
- , subq_17.buy__ds__extract_day
- , subq_17.buy__ds__extract_dow
- , subq_17.buy__ds__extract_doy
- , subq_17.metric_time__day
- , subq_17.metric_time__week
- , subq_17.metric_time__month
- , subq_17.metric_time__quarter
- , subq_17.metric_time__year
- , subq_17.metric_time__extract_year
- , subq_17.metric_time__extract_quarter
- , subq_17.metric_time__extract_month
- , subq_17.metric_time__extract_day
- , subq_17.metric_time__extract_dow
- , subq_17.metric_time__extract_doy
- , subq_17.user
- , subq_17.session_id
- , subq_17.buy__user
- , subq_17.buy__session_id
- , subq_17.buys
- , subq_17.buyers
- , GEN_RANDOM_UUID() AS mf_internal_uuid
- FROM (
- -- Metric Time Dimension 'ds'
+ subq_11.ds__day AS ds__day
+ , subq_11.ds__week AS ds__week
+ , subq_11.ds__month AS ds__month
+ , subq_11.ds__quarter AS ds__quarter
+ , subq_11.ds__year AS ds__year
+ , subq_11.ds__extract_year AS ds__extract_year
+ , subq_11.ds__extract_quarter AS ds__extract_quarter
+ , subq_11.ds__extract_month AS ds__extract_month
+ , subq_11.ds__extract_day AS ds__extract_day
+ , subq_11.ds__extract_dow AS ds__extract_dow
+ , subq_11.ds__extract_doy AS ds__extract_doy
+ , subq_11.visit__ds__day AS visit__ds__day
+ , subq_11.visit__ds__week AS visit__ds__week
+ , subq_11.visit__ds__month AS visit__ds__month
+ , subq_11.visit__ds__quarter AS visit__ds__quarter
+ , subq_11.visit__ds__year AS visit__ds__year
+ , subq_11.visit__ds__extract_year AS visit__ds__extract_year
+ , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
+ , subq_11.visit__ds__extract_month AS visit__ds__extract_month
+ , subq_11.visit__ds__extract_day AS visit__ds__extract_day
+ , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
+ , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
+ , subq_11.metric_time__day AS metric_time__day
+ , subq_11.metric_time__week AS metric_time__week
+ , subq_11.metric_time__month AS metric_time__month
+ , subq_11.metric_time__quarter AS metric_time__quarter
+ , subq_11.metric_time__year AS metric_time__year
+ , subq_11.metric_time__extract_year AS metric_time__extract_year
+ , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_11.metric_time__extract_month AS metric_time__extract_month
+ , subq_11.metric_time__extract_day AS metric_time__extract_day
+ , subq_11.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_11.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_11.user AS user
+ , subq_11.session AS session
+ , subq_11.visit__user AS visit__user
+ , subq_11.visit__session AS visit__session
+ , subq_11.referrer_id AS referrer_id
+ , subq_11.visit__referrer_id AS visit__referrer_id
+ , subq_13.home_state_latest AS user__home_state_latest
+ , subq_11.visits AS visits
+ , subq_11.visitors AS visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.visit__ds__day
+ , subq_10.visit__ds__week
+ , subq_10.visit__ds__month
+ , subq_10.visit__ds__quarter
+ , subq_10.visit__ds__year
+ , subq_10.visit__ds__extract_year
+ , subq_10.visit__ds__extract_quarter
+ , subq_10.visit__ds__extract_month
+ , subq_10.visit__ds__extract_day
+ , subq_10.visit__ds__extract_dow
+ , subq_10.visit__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session
+ , subq_10.visit__user
+ , subq_10.visit__session
+ , subq_10.referrer_id
+ , subq_10.visit__referrer_id
+ , subq_10.visits
+ , subq_10.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_10
+ ) subq_11
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_12.user
+ , subq_12.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_12
+ ) subq_13
+ ON
+ subq_11.user = subq_13.user
+ ) subq_14
+ WHERE visit__referrer_id = '123456'
+ ) subq_15
+ ) subq_16
+ INNER JOIN (
+ -- Add column with generated UUID
SELECT
- subq_16.ds__day
- , subq_16.ds__week
- , subq_16.ds__month
- , subq_16.ds__quarter
- , subq_16.ds__year
- , subq_16.ds__extract_year
- , subq_16.ds__extract_quarter
- , subq_16.ds__extract_month
- , subq_16.ds__extract_day
- , subq_16.ds__extract_dow
- , subq_16.ds__extract_doy
- , subq_16.buy__ds__day
- , subq_16.buy__ds__week
- , subq_16.buy__ds__month
- , subq_16.buy__ds__quarter
- , subq_16.buy__ds__year
- , subq_16.buy__ds__extract_year
- , subq_16.buy__ds__extract_quarter
- , subq_16.buy__ds__extract_month
- , subq_16.buy__ds__extract_day
- , subq_16.buy__ds__extract_dow
- , subq_16.buy__ds__extract_doy
- , subq_16.ds__day AS metric_time__day
- , subq_16.ds__week AS metric_time__week
- , subq_16.ds__month AS metric_time__month
- , subq_16.ds__quarter AS metric_time__quarter
- , subq_16.ds__year AS metric_time__year
- , subq_16.ds__extract_year AS metric_time__extract_year
- , subq_16.ds__extract_quarter AS metric_time__extract_quarter
- , subq_16.ds__extract_month AS metric_time__extract_month
- , subq_16.ds__extract_day AS metric_time__extract_day
- , subq_16.ds__extract_dow AS metric_time__extract_dow
- , subq_16.ds__extract_doy AS metric_time__extract_doy
- , subq_16.user
- , subq_16.session_id
- , subq_16.buy__user
- , subq_16.buy__session_id
- , subq_16.buys
- , subq_16.buyers
+ subq_18.ds__day
+ , subq_18.ds__week
+ , subq_18.ds__month
+ , subq_18.ds__quarter
+ , subq_18.ds__year
+ , subq_18.ds__extract_year
+ , subq_18.ds__extract_quarter
+ , subq_18.ds__extract_month
+ , subq_18.ds__extract_day
+ , subq_18.ds__extract_dow
+ , subq_18.ds__extract_doy
+ , subq_18.buy__ds__day
+ , subq_18.buy__ds__week
+ , subq_18.buy__ds__month
+ , subq_18.buy__ds__quarter
+ , subq_18.buy__ds__year
+ , subq_18.buy__ds__extract_year
+ , subq_18.buy__ds__extract_quarter
+ , subq_18.buy__ds__extract_month
+ , subq_18.buy__ds__extract_day
+ , subq_18.buy__ds__extract_dow
+ , subq_18.buy__ds__extract_doy
+ , subq_18.metric_time__day
+ , subq_18.metric_time__week
+ , subq_18.metric_time__month
+ , subq_18.metric_time__quarter
+ , subq_18.metric_time__year
+ , subq_18.metric_time__extract_year
+ , subq_18.metric_time__extract_quarter
+ , subq_18.metric_time__extract_month
+ , subq_18.metric_time__extract_day
+ , subq_18.metric_time__extract_dow
+ , subq_18.metric_time__extract_doy
+ , subq_18.user
+ , subq_18.session_id
+ , subq_18.buy__user
+ , subq_18.buy__session_id
+ , subq_18.buys
+ , subq_18.buyers
+ , GEN_RANDOM_UUID() AS mf_internal_uuid
FROM (
- -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS buys
- , buys_source_src_28000.user_id AS buyers
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
- , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
- , buys_source_src_28000.user_id AS user
- , buys_source_src_28000.session_id
- , buys_source_src_28000.user_id AS buy__user
- , buys_source_src_28000.session_id AS buy__session_id
- FROM ***************************.fct_buys buys_source_src_28000
- ) subq_16
- ) subq_17
- ) subq_18
- ON
- (
- subq_15.user = subq_18.user
- ) AND (
+ subq_17.ds__day
+ , subq_17.ds__week
+ , subq_17.ds__month
+ , subq_17.ds__quarter
+ , subq_17.ds__year
+ , subq_17.ds__extract_year
+ , subq_17.ds__extract_quarter
+ , subq_17.ds__extract_month
+ , subq_17.ds__extract_day
+ , subq_17.ds__extract_dow
+ , subq_17.ds__extract_doy
+ , subq_17.buy__ds__day
+ , subq_17.buy__ds__week
+ , subq_17.buy__ds__month
+ , subq_17.buy__ds__quarter
+ , subq_17.buy__ds__year
+ , subq_17.buy__ds__extract_year
+ , subq_17.buy__ds__extract_quarter
+ , subq_17.buy__ds__extract_month
+ , subq_17.buy__ds__extract_day
+ , subq_17.buy__ds__extract_dow
+ , subq_17.buy__ds__extract_doy
+ , subq_17.ds__day AS metric_time__day
+ , subq_17.ds__week AS metric_time__week
+ , subq_17.ds__month AS metric_time__month
+ , subq_17.ds__quarter AS metric_time__quarter
+ , subq_17.ds__year AS metric_time__year
+ , subq_17.ds__extract_year AS metric_time__extract_year
+ , subq_17.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_17.ds__extract_month AS metric_time__extract_month
+ , subq_17.ds__extract_day AS metric_time__extract_day
+ , subq_17.ds__extract_dow AS metric_time__extract_dow
+ , subq_17.ds__extract_doy AS metric_time__extract_doy
+ , subq_17.user
+ , subq_17.session_id
+ , subq_17.buy__user
+ , subq_17.buy__session_id
+ , subq_17.buys
+ , subq_17.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_17
+ ) subq_18
+ ) subq_19
+ ON
(
- subq_15.ds__day <= subq_18.ds__day
+ subq_16.user = subq_19.user
) AND (
- subq_15.ds__day > subq_18.ds__day - MAKE_INTERVAL(days => 7)
+ (
+ subq_16.ds__day <= subq_19.ds__day
+ ) AND (
+ subq_16.ds__day > subq_19.ds__day - MAKE_INTERVAL(days => 7)
+ )
)
- )
- ) subq_19
- ) subq_20
- ) subq_21
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
- SELECT
- subq_22.user
- , subq_22.home_state_latest
- FROM (
- -- Read Elements From Semantic Model 'users_latest'
- SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_20
+ ) subq_21
) subq_22
- ) subq_23
- ON
- subq_21.user = subq_23.user
- ) subq_24
- ) subq_25
- GROUP BY
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- ) subq_26
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_23.user
+ , subq_23.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_23
+ ) subq_24
+ ON
+ subq_22.user = subq_24.user
+ ) subq_25
+ ) subq_26
+ GROUP BY
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ ) subq_27
+ ) subq_28
ON
(
- subq_9.user__home_state_latest = subq_26.user__home_state_latest
+ subq_9.user__home_state_latest = subq_28.user__home_state_latest
) AND (
- subq_9.metric_time__day = subq_26.metric_time__day
+ subq_9.metric_time__day = subq_28.metric_time__day
)
GROUP BY
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day)
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest)
-) subq_27
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day)
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest)
+) subq_29
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_query_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_query_filters__plan0_optimized.sql
index 64717e94ef..e8e4ca2cf5 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_query_filters__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_query_filters__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day) AS metric_time__day
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest) AS user__home_state_latest
- , MAX(subq_37.visits) AS visits
- , MAX(subq_54.buys) AS buys
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day) AS metric_time__day
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest) AS user__home_state_latest
+ , MAX(subq_39.visits) AS visits
+ , MAX(subq_58.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'metric_time__day']
@@ -22,10 +22,10 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_30.metric_time__day AS metric_time__day
- , subq_30.visit__referrer_id AS visit__referrer_id
+ subq_32.metric_time__day AS metric_time__day
+ , subq_32.visit__referrer_id AS visit__referrer_id
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_30.visits AS visits
+ , subq_32.visits AS visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
@@ -36,104 +36,116 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_30
+ ) subq_32
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_30.user = users_latest_src_28000.user_id
- ) subq_34
+ subq_32.user = users_latest_src_28000.user_id
+ ) subq_36
WHERE visit__referrer_id = '123456'
GROUP BY
metric_time__day
, user__home_state_latest
- ) subq_37
+ ) subq_39
FULL OUTER JOIN (
-- Join Standard Outputs
-- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
-- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_47.metric_time__day AS metric_time__day
+ subq_50.metric_time__day AS metric_time__day
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , SUM(subq_47.buys) AS buys
+ , SUM(subq_50.buys) AS buys
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_43.visits) OVER (
+ FIRST_VALUE(subq_46.visits) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_43.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_46.visit__referrer_id) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_43.user__home_state_latest) OVER (
+ , FIRST_VALUE(subq_46.user__home_state_latest) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user__home_state_latest
- , FIRST_VALUE(subq_43.ds__day) OVER (
+ , FIRST_VALUE(subq_46.ds__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_43.metric_time__day) OVER (
+ , FIRST_VALUE(subq_46.metric_time__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_43.user) OVER (
+ , FIRST_VALUE(subq_46.user) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_46.mf_internal_uuid AS mf_internal_uuid
- , subq_46.buys AS buys
+ , subq_49.mf_internal_uuid AS mf_internal_uuid
+ , subq_49.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_39.ds__day AS ds__day
- , subq_39.metric_time__day AS metric_time__day
- , subq_39.user AS user
- , subq_39.visit__referrer_id AS visit__referrer_id
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_39.visits AS visits
+ ds__day
+ , metric_time__day
+ , subq_44.user
+ , visit__referrer_id
+ , user__home_state_latest
+ , visits
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , DATE_TRUNC('day', ds) 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_39
- LEFT OUTER JOIN
- ***************************.dim_users_latest users_latest_src_28000
- ON
- subq_39.user = users_latest_src_28000.user_id
- ) subq_43
+ subq_41.ds__day AS ds__day
+ , subq_41.metric_time__day AS metric_time__day
+ , subq_41.user AS user
+ , subq_41.visit__referrer_id AS visit__referrer_id
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , subq_41.visits AS visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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_41
+ LEFT OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_28000
+ ON
+ subq_41.user = users_latest_src_28000.user_id
+ ) subq_44
+ WHERE visit__referrer_id = '123456'
+ ) subq_46
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -144,33 +156,33 @@ FROM (
, 1 AS buys
, GEN_RANDOM_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_46
+ ) subq_49
ON
(
- subq_43.user = subq_46.user
+ subq_46.user = subq_49.user
) AND (
(
- subq_43.ds__day <= subq_46.ds__day
+ subq_46.ds__day <= subq_49.ds__day
) AND (
- subq_43.ds__day > subq_46.ds__day - MAKE_INTERVAL(days => 7)
+ subq_46.ds__day > subq_49.ds__day - MAKE_INTERVAL(days => 7)
)
)
- ) subq_47
+ ) subq_50
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_47.user = users_latest_src_28000.user_id
+ subq_50.user = users_latest_src_28000.user_id
GROUP BY
- subq_47.metric_time__day
+ subq_50.metric_time__day
, users_latest_src_28000.home_state_latest
- ) subq_54
+ ) subq_58
ON
(
- subq_37.user__home_state_latest = subq_54.user__home_state_latest
+ subq_39.user__home_state_latest = subq_58.user__home_state_latest
) AND (
- subq_37.metric_time__day = subq_54.metric_time__day
+ subq_39.metric_time__day = subq_58.metric_time__day
)
GROUP BY
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day)
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest)
-) subq_55
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day)
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest)
+) subq_59
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_query_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_query_filters__plan0.sql
index eaa5a32f5c..4681cf625b 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_query_filters__plan0.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_query_filters__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_27.metric_time__day
- , subq_27.user__home_state_latest
- , CAST(subq_27.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_27.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
+ subq_29.metric_time__day
+ , subq_29.user__home_state_latest
+ , CAST(subq_29.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_29.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day) AS metric_time__day
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest) AS user__home_state_latest
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day) AS metric_time__day
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest) AS user__home_state_latest
, MAX(subq_9.visits) AS visits
- , MAX(subq_26.buys) AS buys
+ , MAX(subq_28.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -180,453 +180,507 @@ FROM (
, subq_8.user__home_state_latest
) subq_9
FULL OUTER JOIN (
- -- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- , SUM(subq_25.buys) AS buys
+ subq_27.metric_time__day
+ , subq_27.user__home_state_latest
+ , subq_27.buys
FROM (
- -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
+ -- Aggregate Measures
SELECT
- subq_24.metric_time__day
- , subq_24.user__home_state_latest
- , subq_24.buys
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ , SUM(subq_26.buys) AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_21.metric_time__day AS metric_time__day
- , subq_21.user AS user
- , subq_21.visit__referrer_id AS visit__referrer_id
- , subq_23.home_state_latest AS user__home_state_latest
- , subq_21.buys AS buys
+ subq_25.metric_time__day
+ , subq_25.user__home_state_latest
+ , subq_25.buys
FROM (
- -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
+ -- Join Standard Outputs
SELECT
- subq_20.metric_time__day
- , subq_20.user
- , subq_20.visit__referrer_id
- , subq_20.buys
+ subq_22.metric_time__day AS metric_time__day
+ , subq_22.user AS user
+ , subq_22.visit__referrer_id AS visit__referrer_id
+ , subq_24.home_state_latest AS user__home_state_latest
+ , subq_22.buys AS buys
FROM (
- -- Find conversions for user within the range of 7 day
+ -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
SELECT
- subq_19.ds__day
- , subq_19.metric_time__day
- , subq_19.user
- , subq_19.visit__referrer_id
- , subq_19.user__home_state_latest
- , subq_19.buys
- , subq_19.visits
+ subq_21.metric_time__day
+ , subq_21.user
+ , subq_21.visit__referrer_id
+ , subq_21.buys
FROM (
- -- Dedupe the fanout with mf_internal_uuid in the conversion data set
- SELECT DISTINCT
- FIRST_VALUE(subq_15.visits) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visits
- , FIRST_VALUE(subq_15.visit__referrer_id) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visit__referrer_id
- , FIRST_VALUE(subq_15.user__home_state_latest) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user__home_state_latest
- , FIRST_VALUE(subq_15.ds__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS ds__day
- , FIRST_VALUE(subq_15.metric_time__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS metric_time__day
- , FIRST_VALUE(subq_15.user) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user
- , subq_18.mf_internal_uuid AS mf_internal_uuid
- , subq_18.buys AS buys
+ -- Find conversions for user within the range of 7 day
+ SELECT
+ subq_20.ds__day
+ , subq_20.metric_time__day
+ , subq_20.user
+ , subq_20.visit__referrer_id
+ , subq_20.user__home_state_latest
+ , subq_20.buys
+ , subq_20.visits
FROM (
- -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
- SELECT
- subq_14.ds__day
- , subq_14.metric_time__day
- , subq_14.user
- , subq_14.visit__referrer_id
- , subq_14.user__home_state_latest
- , subq_14.visits
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_16.visits) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_16.visit__referrer_id) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visit__referrer_id
+ , FIRST_VALUE(subq_16.user__home_state_latest) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user__home_state_latest
+ , FIRST_VALUE(subq_16.ds__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_16.metric_time__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_16.user) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_19.mf_internal_uuid AS mf_internal_uuid
+ , subq_19.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_11.ds__day AS ds__day
- , subq_11.ds__week AS ds__week
- , subq_11.ds__month AS ds__month
- , subq_11.ds__quarter AS ds__quarter
- , subq_11.ds__year AS ds__year
- , subq_11.ds__extract_year AS ds__extract_year
- , subq_11.ds__extract_quarter AS ds__extract_quarter
- , subq_11.ds__extract_month AS ds__extract_month
- , subq_11.ds__extract_day AS ds__extract_day
- , subq_11.ds__extract_dow AS ds__extract_dow
- , subq_11.ds__extract_doy AS ds__extract_doy
- , subq_11.visit__ds__day AS visit__ds__day
- , subq_11.visit__ds__week AS visit__ds__week
- , subq_11.visit__ds__month AS visit__ds__month
- , subq_11.visit__ds__quarter AS visit__ds__quarter
- , subq_11.visit__ds__year AS visit__ds__year
- , subq_11.visit__ds__extract_year AS visit__ds__extract_year
- , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
- , subq_11.visit__ds__extract_month AS visit__ds__extract_month
- , subq_11.visit__ds__extract_day AS visit__ds__extract_day
- , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
- , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
- , subq_11.metric_time__day AS metric_time__day
- , subq_11.metric_time__week AS metric_time__week
- , subq_11.metric_time__month AS metric_time__month
- , subq_11.metric_time__quarter AS metric_time__quarter
- , subq_11.metric_time__year AS metric_time__year
- , subq_11.metric_time__extract_year AS metric_time__extract_year
- , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
- , subq_11.metric_time__extract_month AS metric_time__extract_month
- , subq_11.metric_time__extract_day AS metric_time__extract_day
- , subq_11.metric_time__extract_dow AS metric_time__extract_dow
- , subq_11.metric_time__extract_doy AS metric_time__extract_doy
- , subq_11.user AS user
- , subq_11.session AS session
- , subq_11.visit__user AS visit__user
- , subq_11.visit__session AS visit__session
- , subq_11.referrer_id AS referrer_id
- , subq_11.visit__referrer_id AS visit__referrer_id
- , subq_13.home_state_latest AS user__home_state_latest
- , subq_11.visits AS visits
- , subq_11.visitors AS visitors
+ subq_15.ds__day
+ , subq_15.metric_time__day
+ , subq_15.user
+ , subq_15.visit__referrer_id
+ , subq_15.user__home_state_latest
+ , subq_15.visits
FROM (
- -- Metric Time Dimension 'ds'
- SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.visit__ds__day
- , subq_10.visit__ds__week
- , subq_10.visit__ds__month
- , subq_10.visit__ds__quarter
- , subq_10.visit__ds__year
- , subq_10.visit__ds__extract_year
- , subq_10.visit__ds__extract_quarter
- , subq_10.visit__ds__extract_month
- , subq_10.visit__ds__extract_day
- , subq_10.visit__ds__extract_dow
- , subq_10.visit__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session
- , subq_10.visit__user
- , subq_10.visit__session
- , subq_10.referrer_id
- , subq_10.visit__referrer_id
- , subq_10.visits
- , subq_10.visitors
- FROM (
- -- Read Elements From Semantic Model 'visits_source'
- SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_10
- ) subq_11
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
+ -- Constrain Output with WHERE
SELECT
- subq_12.user
- , subq_12.home_state_latest
+ subq_14.ds__day
+ , subq_14.ds__week
+ , subq_14.ds__month
+ , subq_14.ds__quarter
+ , subq_14.ds__year
+ , subq_14.ds__extract_year
+ , subq_14.ds__extract_quarter
+ , subq_14.ds__extract_month
+ , subq_14.ds__extract_day
+ , subq_14.ds__extract_dow
+ , subq_14.ds__extract_doy
+ , subq_14.visit__ds__day
+ , subq_14.visit__ds__week
+ , subq_14.visit__ds__month
+ , subq_14.visit__ds__quarter
+ , subq_14.visit__ds__year
+ , subq_14.visit__ds__extract_year
+ , subq_14.visit__ds__extract_quarter
+ , subq_14.visit__ds__extract_month
+ , subq_14.visit__ds__extract_day
+ , subq_14.visit__ds__extract_dow
+ , subq_14.visit__ds__extract_doy
+ , subq_14.metric_time__day
+ , subq_14.metric_time__week
+ , subq_14.metric_time__month
+ , subq_14.metric_time__quarter
+ , subq_14.metric_time__year
+ , subq_14.metric_time__extract_year
+ , subq_14.metric_time__extract_quarter
+ , subq_14.metric_time__extract_month
+ , subq_14.metric_time__extract_day
+ , subq_14.metric_time__extract_dow
+ , subq_14.metric_time__extract_doy
+ , subq_14.user
+ , subq_14.session
+ , subq_14.visit__user
+ , subq_14.visit__session
+ , subq_14.referrer_id
+ , subq_14.visit__referrer_id
+ , subq_14.user__home_state_latest
+ , subq_14.visits
+ , subq_14.visitors
FROM (
- -- Read Elements From Semantic Model 'users_latest'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
- ) subq_12
- ) subq_13
- ON
- subq_11.user = subq_13.user
- ) subq_14
- ) subq_15
- INNER JOIN (
- -- Add column with generated UUID
- SELECT
- subq_17.ds__day
- , subq_17.ds__week
- , subq_17.ds__month
- , subq_17.ds__quarter
- , subq_17.ds__year
- , subq_17.ds__extract_year
- , subq_17.ds__extract_quarter
- , subq_17.ds__extract_month
- , subq_17.ds__extract_day
- , subq_17.ds__extract_dow
- , subq_17.ds__extract_doy
- , subq_17.buy__ds__day
- , subq_17.buy__ds__week
- , subq_17.buy__ds__month
- , subq_17.buy__ds__quarter
- , subq_17.buy__ds__year
- , subq_17.buy__ds__extract_year
- , subq_17.buy__ds__extract_quarter
- , subq_17.buy__ds__extract_month
- , subq_17.buy__ds__extract_day
- , subq_17.buy__ds__extract_dow
- , subq_17.buy__ds__extract_doy
- , subq_17.metric_time__day
- , subq_17.metric_time__week
- , subq_17.metric_time__month
- , subq_17.metric_time__quarter
- , subq_17.metric_time__year
- , subq_17.metric_time__extract_year
- , subq_17.metric_time__extract_quarter
- , subq_17.metric_time__extract_month
- , subq_17.metric_time__extract_day
- , subq_17.metric_time__extract_dow
- , subq_17.metric_time__extract_doy
- , subq_17.user
- , subq_17.session_id
- , subq_17.buy__user
- , subq_17.buy__session_id
- , subq_17.buys
- , subq_17.buyers
- , CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
- FROM (
- -- Metric Time Dimension 'ds'
+ subq_11.ds__day AS ds__day
+ , subq_11.ds__week AS ds__week
+ , subq_11.ds__month AS ds__month
+ , subq_11.ds__quarter AS ds__quarter
+ , subq_11.ds__year AS ds__year
+ , subq_11.ds__extract_year AS ds__extract_year
+ , subq_11.ds__extract_quarter AS ds__extract_quarter
+ , subq_11.ds__extract_month AS ds__extract_month
+ , subq_11.ds__extract_day AS ds__extract_day
+ , subq_11.ds__extract_dow AS ds__extract_dow
+ , subq_11.ds__extract_doy AS ds__extract_doy
+ , subq_11.visit__ds__day AS visit__ds__day
+ , subq_11.visit__ds__week AS visit__ds__week
+ , subq_11.visit__ds__month AS visit__ds__month
+ , subq_11.visit__ds__quarter AS visit__ds__quarter
+ , subq_11.visit__ds__year AS visit__ds__year
+ , subq_11.visit__ds__extract_year AS visit__ds__extract_year
+ , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
+ , subq_11.visit__ds__extract_month AS visit__ds__extract_month
+ , subq_11.visit__ds__extract_day AS visit__ds__extract_day
+ , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
+ , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
+ , subq_11.metric_time__day AS metric_time__day
+ , subq_11.metric_time__week AS metric_time__week
+ , subq_11.metric_time__month AS metric_time__month
+ , subq_11.metric_time__quarter AS metric_time__quarter
+ , subq_11.metric_time__year AS metric_time__year
+ , subq_11.metric_time__extract_year AS metric_time__extract_year
+ , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_11.metric_time__extract_month AS metric_time__extract_month
+ , subq_11.metric_time__extract_day AS metric_time__extract_day
+ , subq_11.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_11.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_11.user AS user
+ , subq_11.session AS session
+ , subq_11.visit__user AS visit__user
+ , subq_11.visit__session AS visit__session
+ , subq_11.referrer_id AS referrer_id
+ , subq_11.visit__referrer_id AS visit__referrer_id
+ , subq_13.home_state_latest AS user__home_state_latest
+ , subq_11.visits AS visits
+ , subq_11.visitors AS visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.visit__ds__day
+ , subq_10.visit__ds__week
+ , subq_10.visit__ds__month
+ , subq_10.visit__ds__quarter
+ , subq_10.visit__ds__year
+ , subq_10.visit__ds__extract_year
+ , subq_10.visit__ds__extract_quarter
+ , subq_10.visit__ds__extract_month
+ , subq_10.visit__ds__extract_day
+ , subq_10.visit__ds__extract_dow
+ , subq_10.visit__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session
+ , subq_10.visit__user
+ , subq_10.visit__session
+ , subq_10.referrer_id
+ , subq_10.visit__referrer_id
+ , subq_10.visits
+ , subq_10.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_10
+ ) subq_11
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_12.user
+ , subq_12.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_12
+ ) subq_13
+ ON
+ subq_11.user = subq_13.user
+ ) subq_14
+ WHERE visit__referrer_id = '123456'
+ ) subq_15
+ ) subq_16
+ INNER JOIN (
+ -- Add column with generated UUID
SELECT
- subq_16.ds__day
- , subq_16.ds__week
- , subq_16.ds__month
- , subq_16.ds__quarter
- , subq_16.ds__year
- , subq_16.ds__extract_year
- , subq_16.ds__extract_quarter
- , subq_16.ds__extract_month
- , subq_16.ds__extract_day
- , subq_16.ds__extract_dow
- , subq_16.ds__extract_doy
- , subq_16.buy__ds__day
- , subq_16.buy__ds__week
- , subq_16.buy__ds__month
- , subq_16.buy__ds__quarter
- , subq_16.buy__ds__year
- , subq_16.buy__ds__extract_year
- , subq_16.buy__ds__extract_quarter
- , subq_16.buy__ds__extract_month
- , subq_16.buy__ds__extract_day
- , subq_16.buy__ds__extract_dow
- , subq_16.buy__ds__extract_doy
- , subq_16.ds__day AS metric_time__day
- , subq_16.ds__week AS metric_time__week
- , subq_16.ds__month AS metric_time__month
- , subq_16.ds__quarter AS metric_time__quarter
- , subq_16.ds__year AS metric_time__year
- , subq_16.ds__extract_year AS metric_time__extract_year
- , subq_16.ds__extract_quarter AS metric_time__extract_quarter
- , subq_16.ds__extract_month AS metric_time__extract_month
- , subq_16.ds__extract_day AS metric_time__extract_day
- , subq_16.ds__extract_dow AS metric_time__extract_dow
- , subq_16.ds__extract_doy AS metric_time__extract_doy
- , subq_16.user
- , subq_16.session_id
- , subq_16.buy__user
- , subq_16.buy__session_id
- , subq_16.buys
- , subq_16.buyers
+ subq_18.ds__day
+ , subq_18.ds__week
+ , subq_18.ds__month
+ , subq_18.ds__quarter
+ , subq_18.ds__year
+ , subq_18.ds__extract_year
+ , subq_18.ds__extract_quarter
+ , subq_18.ds__extract_month
+ , subq_18.ds__extract_day
+ , subq_18.ds__extract_dow
+ , subq_18.ds__extract_doy
+ , subq_18.buy__ds__day
+ , subq_18.buy__ds__week
+ , subq_18.buy__ds__month
+ , subq_18.buy__ds__quarter
+ , subq_18.buy__ds__year
+ , subq_18.buy__ds__extract_year
+ , subq_18.buy__ds__extract_quarter
+ , subq_18.buy__ds__extract_month
+ , subq_18.buy__ds__extract_day
+ , subq_18.buy__ds__extract_dow
+ , subq_18.buy__ds__extract_doy
+ , subq_18.metric_time__day
+ , subq_18.metric_time__week
+ , subq_18.metric_time__month
+ , subq_18.metric_time__quarter
+ , subq_18.metric_time__year
+ , subq_18.metric_time__extract_year
+ , subq_18.metric_time__extract_quarter
+ , subq_18.metric_time__extract_month
+ , subq_18.metric_time__extract_day
+ , subq_18.metric_time__extract_dow
+ , subq_18.metric_time__extract_doy
+ , subq_18.user
+ , subq_18.session_id
+ , subq_18.buy__user
+ , subq_18.buy__session_id
+ , subq_18.buys
+ , subq_18.buyers
+ , CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM (
- -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS buys
- , buys_source_src_28000.user_id AS buyers
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
- , CASE WHEN EXTRACT(dow FROM buys_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM buys_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM buys_source_src_28000.ds) END AS ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
- , CASE WHEN EXTRACT(dow FROM buys_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM buys_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM buys_source_src_28000.ds) END AS buy__ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
- , buys_source_src_28000.user_id AS user
- , buys_source_src_28000.session_id
- , buys_source_src_28000.user_id AS buy__user
- , buys_source_src_28000.session_id AS buy__session_id
- FROM ***************************.fct_buys buys_source_src_28000
- ) subq_16
- ) subq_17
- ) subq_18
- ON
- (
- subq_15.user = subq_18.user
- ) AND (
+ subq_17.ds__day
+ , subq_17.ds__week
+ , subq_17.ds__month
+ , subq_17.ds__quarter
+ , subq_17.ds__year
+ , subq_17.ds__extract_year
+ , subq_17.ds__extract_quarter
+ , subq_17.ds__extract_month
+ , subq_17.ds__extract_day
+ , subq_17.ds__extract_dow
+ , subq_17.ds__extract_doy
+ , subq_17.buy__ds__day
+ , subq_17.buy__ds__week
+ , subq_17.buy__ds__month
+ , subq_17.buy__ds__quarter
+ , subq_17.buy__ds__year
+ , subq_17.buy__ds__extract_year
+ , subq_17.buy__ds__extract_quarter
+ , subq_17.buy__ds__extract_month
+ , subq_17.buy__ds__extract_day
+ , subq_17.buy__ds__extract_dow
+ , subq_17.buy__ds__extract_doy
+ , subq_17.ds__day AS metric_time__day
+ , subq_17.ds__week AS metric_time__week
+ , subq_17.ds__month AS metric_time__month
+ , subq_17.ds__quarter AS metric_time__quarter
+ , subq_17.ds__year AS metric_time__year
+ , subq_17.ds__extract_year AS metric_time__extract_year
+ , subq_17.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_17.ds__extract_month AS metric_time__extract_month
+ , subq_17.ds__extract_day AS metric_time__extract_day
+ , subq_17.ds__extract_dow AS metric_time__extract_dow
+ , subq_17.ds__extract_doy AS metric_time__extract_doy
+ , subq_17.user
+ , subq_17.session_id
+ , subq_17.buy__user
+ , subq_17.buy__session_id
+ , subq_17.buys
+ , subq_17.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM buys_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM buys_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM buys_source_src_28000.ds) END AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , CASE WHEN EXTRACT(dow FROM buys_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM buys_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM buys_source_src_28000.ds) END AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_17
+ ) subq_18
+ ) subq_19
+ ON
(
- subq_15.ds__day <= subq_18.ds__day
+ subq_16.user = subq_19.user
) AND (
- subq_15.ds__day > DATEADD(day, -7, subq_18.ds__day)
+ (
+ subq_16.ds__day <= subq_19.ds__day
+ ) AND (
+ subq_16.ds__day > DATEADD(day, -7, subq_19.ds__day)
+ )
)
- )
- ) subq_19
- ) subq_20
- ) subq_21
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
- SELECT
- subq_22.user
- , subq_22.home_state_latest
- FROM (
- -- Read Elements From Semantic Model 'users_latest'
- SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_20
+ ) subq_21
) subq_22
- ) subq_23
- ON
- subq_21.user = subq_23.user
- ) subq_24
- ) subq_25
- GROUP BY
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- ) subq_26
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_23.user
+ , subq_23.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_23
+ ) subq_24
+ ON
+ subq_22.user = subq_24.user
+ ) subq_25
+ ) subq_26
+ GROUP BY
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ ) subq_27
+ ) subq_28
ON
(
- subq_9.user__home_state_latest = subq_26.user__home_state_latest
+ subq_9.user__home_state_latest = subq_28.user__home_state_latest
) AND (
- subq_9.metric_time__day = subq_26.metric_time__day
+ subq_9.metric_time__day = subq_28.metric_time__day
)
GROUP BY
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day)
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest)
-) subq_27
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day)
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest)
+) subq_29
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_query_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_query_filters__plan0_optimized.sql
index 21e5bde3f3..b8d7dd090f 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_query_filters__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_query_filters__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day) AS metric_time__day
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest) AS user__home_state_latest
- , MAX(subq_37.visits) AS visits
- , MAX(subq_54.buys) AS buys
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day) AS metric_time__day
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest) AS user__home_state_latest
+ , MAX(subq_39.visits) AS visits
+ , MAX(subq_58.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'metric_time__day']
@@ -22,10 +22,10 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_30.metric_time__day AS metric_time__day
- , subq_30.visit__referrer_id AS visit__referrer_id
+ subq_32.metric_time__day AS metric_time__day
+ , subq_32.visit__referrer_id AS visit__referrer_id
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_30.visits AS visits
+ , subq_32.visits AS visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
@@ -36,104 +36,116 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_30
+ ) subq_32
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_30.user = users_latest_src_28000.user_id
- ) subq_34
+ subq_32.user = users_latest_src_28000.user_id
+ ) subq_36
WHERE visit__referrer_id = '123456'
GROUP BY
metric_time__day
, user__home_state_latest
- ) subq_37
+ ) subq_39
FULL OUTER JOIN (
-- Join Standard Outputs
-- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
-- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_47.metric_time__day AS metric_time__day
+ subq_50.metric_time__day AS metric_time__day
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , SUM(subq_47.buys) AS buys
+ , SUM(subq_50.buys) AS buys
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_43.visits) OVER (
+ FIRST_VALUE(subq_46.visits) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_43.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_46.visit__referrer_id) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_43.user__home_state_latest) OVER (
+ , FIRST_VALUE(subq_46.user__home_state_latest) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user__home_state_latest
- , FIRST_VALUE(subq_43.ds__day) OVER (
+ , FIRST_VALUE(subq_46.ds__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_43.metric_time__day) OVER (
+ , FIRST_VALUE(subq_46.metric_time__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_43.user) OVER (
+ , FIRST_VALUE(subq_46.user) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_46.mf_internal_uuid AS mf_internal_uuid
- , subq_46.buys AS buys
+ , subq_49.mf_internal_uuid AS mf_internal_uuid
+ , subq_49.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_39.ds__day AS ds__day
- , subq_39.metric_time__day AS metric_time__day
- , subq_39.user AS user
- , subq_39.visit__referrer_id AS visit__referrer_id
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_39.visits AS visits
+ ds__day
+ , metric_time__day
+ , subq_44.user
+ , visit__referrer_id
+ , user__home_state_latest
+ , visits
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , DATE_TRUNC('day', ds) 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_39
- LEFT OUTER JOIN
- ***************************.dim_users_latest users_latest_src_28000
- ON
- subq_39.user = users_latest_src_28000.user_id
- ) subq_43
+ subq_41.ds__day AS ds__day
+ , subq_41.metric_time__day AS metric_time__day
+ , subq_41.user AS user
+ , subq_41.visit__referrer_id AS visit__referrer_id
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , subq_41.visits AS visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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_41
+ LEFT OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_28000
+ ON
+ subq_41.user = users_latest_src_28000.user_id
+ ) subq_44
+ WHERE visit__referrer_id = '123456'
+ ) subq_46
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -144,33 +156,33 @@ FROM (
, 1 AS buys
, CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_46
+ ) subq_49
ON
(
- subq_43.user = subq_46.user
+ subq_46.user = subq_49.user
) AND (
(
- subq_43.ds__day <= subq_46.ds__day
+ subq_46.ds__day <= subq_49.ds__day
) AND (
- subq_43.ds__day > DATEADD(day, -7, subq_46.ds__day)
+ subq_46.ds__day > DATEADD(day, -7, subq_49.ds__day)
)
)
- ) subq_47
+ ) subq_50
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_47.user = users_latest_src_28000.user_id
+ subq_50.user = users_latest_src_28000.user_id
GROUP BY
- subq_47.metric_time__day
+ subq_50.metric_time__day
, users_latest_src_28000.home_state_latest
- ) subq_54
+ ) subq_58
ON
(
- subq_37.user__home_state_latest = subq_54.user__home_state_latest
+ subq_39.user__home_state_latest = subq_58.user__home_state_latest
) AND (
- subq_37.metric_time__day = subq_54.metric_time__day
+ subq_39.metric_time__day = subq_58.metric_time__day
)
GROUP BY
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day)
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest)
-) subq_55
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day)
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest)
+) subq_59
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_query_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_query_filters__plan0.sql
index e21168d214..9696e5feac 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_query_filters__plan0.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_query_filters__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_27.metric_time__day
- , subq_27.user__home_state_latest
- , CAST(subq_27.buys AS DOUBLE) / CAST(NULLIF(subq_27.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_29.metric_time__day
+ , subq_29.user__home_state_latest
+ , CAST(subq_29.buys AS DOUBLE) / CAST(NULLIF(subq_29.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day) AS metric_time__day
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest) AS user__home_state_latest
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day) AS metric_time__day
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest) AS user__home_state_latest
, MAX(subq_9.visits) AS visits
- , MAX(subq_26.buys) AS buys
+ , MAX(subq_28.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -180,453 +180,507 @@ FROM (
, subq_8.user__home_state_latest
) subq_9
FULL OUTER JOIN (
- -- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- , SUM(subq_25.buys) AS buys
+ subq_27.metric_time__day
+ , subq_27.user__home_state_latest
+ , subq_27.buys
FROM (
- -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
+ -- Aggregate Measures
SELECT
- subq_24.metric_time__day
- , subq_24.user__home_state_latest
- , subq_24.buys
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ , SUM(subq_26.buys) AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_21.metric_time__day AS metric_time__day
- , subq_21.user AS user
- , subq_21.visit__referrer_id AS visit__referrer_id
- , subq_23.home_state_latest AS user__home_state_latest
- , subq_21.buys AS buys
+ subq_25.metric_time__day
+ , subq_25.user__home_state_latest
+ , subq_25.buys
FROM (
- -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
+ -- Join Standard Outputs
SELECT
- subq_20.metric_time__day
- , subq_20.user
- , subq_20.visit__referrer_id
- , subq_20.buys
+ subq_22.metric_time__day AS metric_time__day
+ , subq_22.user AS user
+ , subq_22.visit__referrer_id AS visit__referrer_id
+ , subq_24.home_state_latest AS user__home_state_latest
+ , subq_22.buys AS buys
FROM (
- -- Find conversions for user within the range of 7 day
+ -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
SELECT
- subq_19.ds__day
- , subq_19.metric_time__day
- , subq_19.user
- , subq_19.visit__referrer_id
- , subq_19.user__home_state_latest
- , subq_19.buys
- , subq_19.visits
+ subq_21.metric_time__day
+ , subq_21.user
+ , subq_21.visit__referrer_id
+ , subq_21.buys
FROM (
- -- Dedupe the fanout with mf_internal_uuid in the conversion data set
- SELECT DISTINCT
- FIRST_VALUE(subq_15.visits) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visits
- , FIRST_VALUE(subq_15.visit__referrer_id) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visit__referrer_id
- , FIRST_VALUE(subq_15.user__home_state_latest) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user__home_state_latest
- , FIRST_VALUE(subq_15.ds__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS ds__day
- , FIRST_VALUE(subq_15.metric_time__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS metric_time__day
- , FIRST_VALUE(subq_15.user) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user
- , subq_18.mf_internal_uuid AS mf_internal_uuid
- , subq_18.buys AS buys
+ -- Find conversions for user within the range of 7 day
+ SELECT
+ subq_20.ds__day
+ , subq_20.metric_time__day
+ , subq_20.user
+ , subq_20.visit__referrer_id
+ , subq_20.user__home_state_latest
+ , subq_20.buys
+ , subq_20.visits
FROM (
- -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
- SELECT
- subq_14.ds__day
- , subq_14.metric_time__day
- , subq_14.user
- , subq_14.visit__referrer_id
- , subq_14.user__home_state_latest
- , subq_14.visits
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_16.visits) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_16.visit__referrer_id) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visit__referrer_id
+ , FIRST_VALUE(subq_16.user__home_state_latest) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user__home_state_latest
+ , FIRST_VALUE(subq_16.ds__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_16.metric_time__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_16.user) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_19.mf_internal_uuid AS mf_internal_uuid
+ , subq_19.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_11.ds__day AS ds__day
- , subq_11.ds__week AS ds__week
- , subq_11.ds__month AS ds__month
- , subq_11.ds__quarter AS ds__quarter
- , subq_11.ds__year AS ds__year
- , subq_11.ds__extract_year AS ds__extract_year
- , subq_11.ds__extract_quarter AS ds__extract_quarter
- , subq_11.ds__extract_month AS ds__extract_month
- , subq_11.ds__extract_day AS ds__extract_day
- , subq_11.ds__extract_dow AS ds__extract_dow
- , subq_11.ds__extract_doy AS ds__extract_doy
- , subq_11.visit__ds__day AS visit__ds__day
- , subq_11.visit__ds__week AS visit__ds__week
- , subq_11.visit__ds__month AS visit__ds__month
- , subq_11.visit__ds__quarter AS visit__ds__quarter
- , subq_11.visit__ds__year AS visit__ds__year
- , subq_11.visit__ds__extract_year AS visit__ds__extract_year
- , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
- , subq_11.visit__ds__extract_month AS visit__ds__extract_month
- , subq_11.visit__ds__extract_day AS visit__ds__extract_day
- , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
- , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
- , subq_11.metric_time__day AS metric_time__day
- , subq_11.metric_time__week AS metric_time__week
- , subq_11.metric_time__month AS metric_time__month
- , subq_11.metric_time__quarter AS metric_time__quarter
- , subq_11.metric_time__year AS metric_time__year
- , subq_11.metric_time__extract_year AS metric_time__extract_year
- , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
- , subq_11.metric_time__extract_month AS metric_time__extract_month
- , subq_11.metric_time__extract_day AS metric_time__extract_day
- , subq_11.metric_time__extract_dow AS metric_time__extract_dow
- , subq_11.metric_time__extract_doy AS metric_time__extract_doy
- , subq_11.user AS user
- , subq_11.session AS session
- , subq_11.visit__user AS visit__user
- , subq_11.visit__session AS visit__session
- , subq_11.referrer_id AS referrer_id
- , subq_11.visit__referrer_id AS visit__referrer_id
- , subq_13.home_state_latest AS user__home_state_latest
- , subq_11.visits AS visits
- , subq_11.visitors AS visitors
+ subq_15.ds__day
+ , subq_15.metric_time__day
+ , subq_15.user
+ , subq_15.visit__referrer_id
+ , subq_15.user__home_state_latest
+ , subq_15.visits
FROM (
- -- Metric Time Dimension 'ds'
- SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.visit__ds__day
- , subq_10.visit__ds__week
- , subq_10.visit__ds__month
- , subq_10.visit__ds__quarter
- , subq_10.visit__ds__year
- , subq_10.visit__ds__extract_year
- , subq_10.visit__ds__extract_quarter
- , subq_10.visit__ds__extract_month
- , subq_10.visit__ds__extract_day
- , subq_10.visit__ds__extract_dow
- , subq_10.visit__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session
- , subq_10.visit__user
- , subq_10.visit__session
- , subq_10.referrer_id
- , subq_10.visit__referrer_id
- , subq_10.visits
- , subq_10.visitors
- FROM (
- -- Read Elements From Semantic Model 'visits_source'
- SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_10
- ) subq_11
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
+ -- Constrain Output with WHERE
SELECT
- subq_12.user
- , subq_12.home_state_latest
+ subq_14.ds__day
+ , subq_14.ds__week
+ , subq_14.ds__month
+ , subq_14.ds__quarter
+ , subq_14.ds__year
+ , subq_14.ds__extract_year
+ , subq_14.ds__extract_quarter
+ , subq_14.ds__extract_month
+ , subq_14.ds__extract_day
+ , subq_14.ds__extract_dow
+ , subq_14.ds__extract_doy
+ , subq_14.visit__ds__day
+ , subq_14.visit__ds__week
+ , subq_14.visit__ds__month
+ , subq_14.visit__ds__quarter
+ , subq_14.visit__ds__year
+ , subq_14.visit__ds__extract_year
+ , subq_14.visit__ds__extract_quarter
+ , subq_14.visit__ds__extract_month
+ , subq_14.visit__ds__extract_day
+ , subq_14.visit__ds__extract_dow
+ , subq_14.visit__ds__extract_doy
+ , subq_14.metric_time__day
+ , subq_14.metric_time__week
+ , subq_14.metric_time__month
+ , subq_14.metric_time__quarter
+ , subq_14.metric_time__year
+ , subq_14.metric_time__extract_year
+ , subq_14.metric_time__extract_quarter
+ , subq_14.metric_time__extract_month
+ , subq_14.metric_time__extract_day
+ , subq_14.metric_time__extract_dow
+ , subq_14.metric_time__extract_doy
+ , subq_14.user
+ , subq_14.session
+ , subq_14.visit__user
+ , subq_14.visit__session
+ , subq_14.referrer_id
+ , subq_14.visit__referrer_id
+ , subq_14.user__home_state_latest
+ , subq_14.visits
+ , subq_14.visitors
FROM (
- -- Read Elements From Semantic Model 'users_latest'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
- ) subq_12
- ) subq_13
- ON
- subq_11.user = subq_13.user
- ) subq_14
- ) subq_15
- INNER JOIN (
- -- Add column with generated UUID
- SELECT
- subq_17.ds__day
- , subq_17.ds__week
- , subq_17.ds__month
- , subq_17.ds__quarter
- , subq_17.ds__year
- , subq_17.ds__extract_year
- , subq_17.ds__extract_quarter
- , subq_17.ds__extract_month
- , subq_17.ds__extract_day
- , subq_17.ds__extract_dow
- , subq_17.ds__extract_doy
- , subq_17.buy__ds__day
- , subq_17.buy__ds__week
- , subq_17.buy__ds__month
- , subq_17.buy__ds__quarter
- , subq_17.buy__ds__year
- , subq_17.buy__ds__extract_year
- , subq_17.buy__ds__extract_quarter
- , subq_17.buy__ds__extract_month
- , subq_17.buy__ds__extract_day
- , subq_17.buy__ds__extract_dow
- , subq_17.buy__ds__extract_doy
- , subq_17.metric_time__day
- , subq_17.metric_time__week
- , subq_17.metric_time__month
- , subq_17.metric_time__quarter
- , subq_17.metric_time__year
- , subq_17.metric_time__extract_year
- , subq_17.metric_time__extract_quarter
- , subq_17.metric_time__extract_month
- , subq_17.metric_time__extract_day
- , subq_17.metric_time__extract_dow
- , subq_17.metric_time__extract_doy
- , subq_17.user
- , subq_17.session_id
- , subq_17.buy__user
- , subq_17.buy__session_id
- , subq_17.buys
- , subq_17.buyers
- , UUID_STRING() AS mf_internal_uuid
- FROM (
- -- Metric Time Dimension 'ds'
+ subq_11.ds__day AS ds__day
+ , subq_11.ds__week AS ds__week
+ , subq_11.ds__month AS ds__month
+ , subq_11.ds__quarter AS ds__quarter
+ , subq_11.ds__year AS ds__year
+ , subq_11.ds__extract_year AS ds__extract_year
+ , subq_11.ds__extract_quarter AS ds__extract_quarter
+ , subq_11.ds__extract_month AS ds__extract_month
+ , subq_11.ds__extract_day AS ds__extract_day
+ , subq_11.ds__extract_dow AS ds__extract_dow
+ , subq_11.ds__extract_doy AS ds__extract_doy
+ , subq_11.visit__ds__day AS visit__ds__day
+ , subq_11.visit__ds__week AS visit__ds__week
+ , subq_11.visit__ds__month AS visit__ds__month
+ , subq_11.visit__ds__quarter AS visit__ds__quarter
+ , subq_11.visit__ds__year AS visit__ds__year
+ , subq_11.visit__ds__extract_year AS visit__ds__extract_year
+ , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
+ , subq_11.visit__ds__extract_month AS visit__ds__extract_month
+ , subq_11.visit__ds__extract_day AS visit__ds__extract_day
+ , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
+ , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
+ , subq_11.metric_time__day AS metric_time__day
+ , subq_11.metric_time__week AS metric_time__week
+ , subq_11.metric_time__month AS metric_time__month
+ , subq_11.metric_time__quarter AS metric_time__quarter
+ , subq_11.metric_time__year AS metric_time__year
+ , subq_11.metric_time__extract_year AS metric_time__extract_year
+ , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_11.metric_time__extract_month AS metric_time__extract_month
+ , subq_11.metric_time__extract_day AS metric_time__extract_day
+ , subq_11.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_11.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_11.user AS user
+ , subq_11.session AS session
+ , subq_11.visit__user AS visit__user
+ , subq_11.visit__session AS visit__session
+ , subq_11.referrer_id AS referrer_id
+ , subq_11.visit__referrer_id AS visit__referrer_id
+ , subq_13.home_state_latest AS user__home_state_latest
+ , subq_11.visits AS visits
+ , subq_11.visitors AS visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.visit__ds__day
+ , subq_10.visit__ds__week
+ , subq_10.visit__ds__month
+ , subq_10.visit__ds__quarter
+ , subq_10.visit__ds__year
+ , subq_10.visit__ds__extract_year
+ , subq_10.visit__ds__extract_quarter
+ , subq_10.visit__ds__extract_month
+ , subq_10.visit__ds__extract_day
+ , subq_10.visit__ds__extract_dow
+ , subq_10.visit__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session
+ , subq_10.visit__user
+ , subq_10.visit__session
+ , subq_10.referrer_id
+ , subq_10.visit__referrer_id
+ , subq_10.visits
+ , subq_10.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_10
+ ) subq_11
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_12.user
+ , subq_12.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_12
+ ) subq_13
+ ON
+ subq_11.user = subq_13.user
+ ) subq_14
+ WHERE visit__referrer_id = '123456'
+ ) subq_15
+ ) subq_16
+ INNER JOIN (
+ -- Add column with generated UUID
SELECT
- subq_16.ds__day
- , subq_16.ds__week
- , subq_16.ds__month
- , subq_16.ds__quarter
- , subq_16.ds__year
- , subq_16.ds__extract_year
- , subq_16.ds__extract_quarter
- , subq_16.ds__extract_month
- , subq_16.ds__extract_day
- , subq_16.ds__extract_dow
- , subq_16.ds__extract_doy
- , subq_16.buy__ds__day
- , subq_16.buy__ds__week
- , subq_16.buy__ds__month
- , subq_16.buy__ds__quarter
- , subq_16.buy__ds__year
- , subq_16.buy__ds__extract_year
- , subq_16.buy__ds__extract_quarter
- , subq_16.buy__ds__extract_month
- , subq_16.buy__ds__extract_day
- , subq_16.buy__ds__extract_dow
- , subq_16.buy__ds__extract_doy
- , subq_16.ds__day AS metric_time__day
- , subq_16.ds__week AS metric_time__week
- , subq_16.ds__month AS metric_time__month
- , subq_16.ds__quarter AS metric_time__quarter
- , subq_16.ds__year AS metric_time__year
- , subq_16.ds__extract_year AS metric_time__extract_year
- , subq_16.ds__extract_quarter AS metric_time__extract_quarter
- , subq_16.ds__extract_month AS metric_time__extract_month
- , subq_16.ds__extract_day AS metric_time__extract_day
- , subq_16.ds__extract_dow AS metric_time__extract_dow
- , subq_16.ds__extract_doy AS metric_time__extract_doy
- , subq_16.user
- , subq_16.session_id
- , subq_16.buy__user
- , subq_16.buy__session_id
- , subq_16.buys
- , subq_16.buyers
+ subq_18.ds__day
+ , subq_18.ds__week
+ , subq_18.ds__month
+ , subq_18.ds__quarter
+ , subq_18.ds__year
+ , subq_18.ds__extract_year
+ , subq_18.ds__extract_quarter
+ , subq_18.ds__extract_month
+ , subq_18.ds__extract_day
+ , subq_18.ds__extract_dow
+ , subq_18.ds__extract_doy
+ , subq_18.buy__ds__day
+ , subq_18.buy__ds__week
+ , subq_18.buy__ds__month
+ , subq_18.buy__ds__quarter
+ , subq_18.buy__ds__year
+ , subq_18.buy__ds__extract_year
+ , subq_18.buy__ds__extract_quarter
+ , subq_18.buy__ds__extract_month
+ , subq_18.buy__ds__extract_day
+ , subq_18.buy__ds__extract_dow
+ , subq_18.buy__ds__extract_doy
+ , subq_18.metric_time__day
+ , subq_18.metric_time__week
+ , subq_18.metric_time__month
+ , subq_18.metric_time__quarter
+ , subq_18.metric_time__year
+ , subq_18.metric_time__extract_year
+ , subq_18.metric_time__extract_quarter
+ , subq_18.metric_time__extract_month
+ , subq_18.metric_time__extract_day
+ , subq_18.metric_time__extract_dow
+ , subq_18.metric_time__extract_doy
+ , subq_18.user
+ , subq_18.session_id
+ , subq_18.buy__user
+ , subq_18.buy__session_id
+ , subq_18.buys
+ , subq_18.buyers
+ , UUID_STRING() AS mf_internal_uuid
FROM (
- -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS buys
- , buys_source_src_28000.user_id AS buyers
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(dayofweekiso FROM buys_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
- , EXTRACT(dayofweekiso FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
- , buys_source_src_28000.user_id AS user
- , buys_source_src_28000.session_id
- , buys_source_src_28000.user_id AS buy__user
- , buys_source_src_28000.session_id AS buy__session_id
- FROM ***************************.fct_buys buys_source_src_28000
- ) subq_16
- ) subq_17
- ) subq_18
- ON
- (
- subq_15.user = subq_18.user
- ) AND (
+ subq_17.ds__day
+ , subq_17.ds__week
+ , subq_17.ds__month
+ , subq_17.ds__quarter
+ , subq_17.ds__year
+ , subq_17.ds__extract_year
+ , subq_17.ds__extract_quarter
+ , subq_17.ds__extract_month
+ , subq_17.ds__extract_day
+ , subq_17.ds__extract_dow
+ , subq_17.ds__extract_doy
+ , subq_17.buy__ds__day
+ , subq_17.buy__ds__week
+ , subq_17.buy__ds__month
+ , subq_17.buy__ds__quarter
+ , subq_17.buy__ds__year
+ , subq_17.buy__ds__extract_year
+ , subq_17.buy__ds__extract_quarter
+ , subq_17.buy__ds__extract_month
+ , subq_17.buy__ds__extract_day
+ , subq_17.buy__ds__extract_dow
+ , subq_17.buy__ds__extract_doy
+ , subq_17.ds__day AS metric_time__day
+ , subq_17.ds__week AS metric_time__week
+ , subq_17.ds__month AS metric_time__month
+ , subq_17.ds__quarter AS metric_time__quarter
+ , subq_17.ds__year AS metric_time__year
+ , subq_17.ds__extract_year AS metric_time__extract_year
+ , subq_17.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_17.ds__extract_month AS metric_time__extract_month
+ , subq_17.ds__extract_day AS metric_time__extract_day
+ , subq_17.ds__extract_dow AS metric_time__extract_dow
+ , subq_17.ds__extract_doy AS metric_time__extract_doy
+ , subq_17.user
+ , subq_17.session_id
+ , subq_17.buy__user
+ , subq_17.buy__session_id
+ , subq_17.buys
+ , subq_17.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(dayofweekiso FROM buys_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , EXTRACT(dayofweekiso FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_17
+ ) subq_18
+ ) subq_19
+ ON
(
- subq_15.ds__day <= subq_18.ds__day
+ subq_16.user = subq_19.user
) AND (
- subq_15.ds__day > DATEADD(day, -7, subq_18.ds__day)
+ (
+ subq_16.ds__day <= subq_19.ds__day
+ ) AND (
+ subq_16.ds__day > DATEADD(day, -7, subq_19.ds__day)
+ )
)
- )
- ) subq_19
- ) subq_20
- ) subq_21
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
- SELECT
- subq_22.user
- , subq_22.home_state_latest
- FROM (
- -- Read Elements From Semantic Model 'users_latest'
- SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_20
+ ) subq_21
) subq_22
- ) subq_23
- ON
- subq_21.user = subq_23.user
- ) subq_24
- ) subq_25
- GROUP BY
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- ) subq_26
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_23.user
+ , subq_23.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_23
+ ) subq_24
+ ON
+ subq_22.user = subq_24.user
+ ) subq_25
+ ) subq_26
+ GROUP BY
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ ) subq_27
+ ) subq_28
ON
(
- subq_9.user__home_state_latest = subq_26.user__home_state_latest
+ subq_9.user__home_state_latest = subq_28.user__home_state_latest
) AND (
- subq_9.metric_time__day = subq_26.metric_time__day
+ subq_9.metric_time__day = subq_28.metric_time__day
)
GROUP BY
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day)
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest)
-) subq_27
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day)
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest)
+) subq_29
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_query_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_query_filters__plan0_optimized.sql
index 78e9355b9a..a36d21b98e 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_query_filters__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_query_filters__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day) AS metric_time__day
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest) AS user__home_state_latest
- , MAX(subq_37.visits) AS visits
- , MAX(subq_54.buys) AS buys
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day) AS metric_time__day
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest) AS user__home_state_latest
+ , MAX(subq_39.visits) AS visits
+ , MAX(subq_58.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'metric_time__day']
@@ -22,10 +22,10 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_30.metric_time__day AS metric_time__day
- , subq_30.visit__referrer_id AS visit__referrer_id
+ subq_32.metric_time__day AS metric_time__day
+ , subq_32.visit__referrer_id AS visit__referrer_id
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_30.visits AS visits
+ , subq_32.visits AS visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
@@ -36,104 +36,116 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_30
+ ) subq_32
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_30.user = users_latest_src_28000.user_id
- ) subq_34
+ subq_32.user = users_latest_src_28000.user_id
+ ) subq_36
WHERE visit__referrer_id = '123456'
GROUP BY
metric_time__day
, user__home_state_latest
- ) subq_37
+ ) subq_39
FULL OUTER JOIN (
-- Join Standard Outputs
-- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
-- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_47.metric_time__day AS metric_time__day
+ subq_50.metric_time__day AS metric_time__day
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , SUM(subq_47.buys) AS buys
+ , SUM(subq_50.buys) AS buys
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_43.visits) OVER (
+ FIRST_VALUE(subq_46.visits) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_43.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_46.visit__referrer_id) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_43.user__home_state_latest) OVER (
+ , FIRST_VALUE(subq_46.user__home_state_latest) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user__home_state_latest
- , FIRST_VALUE(subq_43.ds__day) OVER (
+ , FIRST_VALUE(subq_46.ds__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_43.metric_time__day) OVER (
+ , FIRST_VALUE(subq_46.metric_time__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_43.user) OVER (
+ , FIRST_VALUE(subq_46.user) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_46.mf_internal_uuid AS mf_internal_uuid
- , subq_46.buys AS buys
+ , subq_49.mf_internal_uuid AS mf_internal_uuid
+ , subq_49.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_39.ds__day AS ds__day
- , subq_39.metric_time__day AS metric_time__day
- , subq_39.user AS user
- , subq_39.visit__referrer_id AS visit__referrer_id
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_39.visits AS visits
+ ds__day
+ , metric_time__day
+ , subq_44.user
+ , visit__referrer_id
+ , user__home_state_latest
+ , visits
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , DATE_TRUNC('day', ds) 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_39
- LEFT OUTER JOIN
- ***************************.dim_users_latest users_latest_src_28000
- ON
- subq_39.user = users_latest_src_28000.user_id
- ) subq_43
+ subq_41.ds__day AS ds__day
+ , subq_41.metric_time__day AS metric_time__day
+ , subq_41.user AS user
+ , subq_41.visit__referrer_id AS visit__referrer_id
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , subq_41.visits AS visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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_41
+ LEFT OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_28000
+ ON
+ subq_41.user = users_latest_src_28000.user_id
+ ) subq_44
+ WHERE visit__referrer_id = '123456'
+ ) subq_46
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -144,33 +156,33 @@ FROM (
, 1 AS buys
, UUID_STRING() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_46
+ ) subq_49
ON
(
- subq_43.user = subq_46.user
+ subq_46.user = subq_49.user
) AND (
(
- subq_43.ds__day <= subq_46.ds__day
+ subq_46.ds__day <= subq_49.ds__day
) AND (
- subq_43.ds__day > DATEADD(day, -7, subq_46.ds__day)
+ subq_46.ds__day > DATEADD(day, -7, subq_49.ds__day)
)
)
- ) subq_47
+ ) subq_50
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_47.user = users_latest_src_28000.user_id
+ subq_50.user = users_latest_src_28000.user_id
GROUP BY
- subq_47.metric_time__day
+ subq_50.metric_time__day
, users_latest_src_28000.home_state_latest
- ) subq_54
+ ) subq_58
ON
(
- subq_37.user__home_state_latest = subq_54.user__home_state_latest
+ subq_39.user__home_state_latest = subq_58.user__home_state_latest
) AND (
- subq_37.metric_time__day = subq_54.metric_time__day
+ subq_39.metric_time__day = subq_58.metric_time__day
)
GROUP BY
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day)
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest)
-) subq_55
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day)
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest)
+) subq_59
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_query_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_query_filters__plan0.sql
index 0c0574cb54..112d77577f 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_query_filters__plan0.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_query_filters__plan0.sql
@@ -1,15 +1,15 @@
-- Compute Metrics via Expressions
SELECT
- subq_27.metric_time__day
- , subq_27.user__home_state_latest
- , CAST(subq_27.buys AS DOUBLE) / CAST(NULLIF(subq_27.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+ subq_29.metric_time__day
+ , subq_29.user__home_state_latest
+ , CAST(subq_29.buys AS DOUBLE) / CAST(NULLIF(subq_29.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day) AS metric_time__day
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest) AS user__home_state_latest
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day) AS metric_time__day
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest) AS user__home_state_latest
, MAX(subq_9.visits) AS visits
- , MAX(subq_26.buys) AS buys
+ , MAX(subq_28.buys) AS buys
FROM (
-- Aggregate Measures
SELECT
@@ -180,453 +180,507 @@ FROM (
, subq_8.user__home_state_latest
) subq_9
FULL OUTER JOIN (
- -- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- , SUM(subq_25.buys) AS buys
+ subq_27.metric_time__day
+ , subq_27.user__home_state_latest
+ , subq_27.buys
FROM (
- -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
+ -- Aggregate Measures
SELECT
- subq_24.metric_time__day
- , subq_24.user__home_state_latest
- , subq_24.buys
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ , SUM(subq_26.buys) AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_21.metric_time__day AS metric_time__day
- , subq_21.user AS user
- , subq_21.visit__referrer_id AS visit__referrer_id
- , subq_23.home_state_latest AS user__home_state_latest
- , subq_21.buys AS buys
+ subq_25.metric_time__day
+ , subq_25.user__home_state_latest
+ , subq_25.buys
FROM (
- -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
+ -- Join Standard Outputs
SELECT
- subq_20.metric_time__day
- , subq_20.user
- , subq_20.visit__referrer_id
- , subq_20.buys
+ subq_22.metric_time__day AS metric_time__day
+ , subq_22.user AS user
+ , subq_22.visit__referrer_id AS visit__referrer_id
+ , subq_24.home_state_latest AS user__home_state_latest
+ , subq_22.buys AS buys
FROM (
- -- Find conversions for user within the range of 7 day
+ -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user']
SELECT
- subq_19.ds__day
- , subq_19.metric_time__day
- , subq_19.user
- , subq_19.visit__referrer_id
- , subq_19.user__home_state_latest
- , subq_19.buys
- , subq_19.visits
+ subq_21.metric_time__day
+ , subq_21.user
+ , subq_21.visit__referrer_id
+ , subq_21.buys
FROM (
- -- Dedupe the fanout with mf_internal_uuid in the conversion data set
- SELECT DISTINCT
- FIRST_VALUE(subq_15.visits) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visits
- , FIRST_VALUE(subq_15.visit__referrer_id) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS visit__referrer_id
- , FIRST_VALUE(subq_15.user__home_state_latest) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user__home_state_latest
- , FIRST_VALUE(subq_15.ds__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS ds__day
- , FIRST_VALUE(subq_15.metric_time__day) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS metric_time__day
- , FIRST_VALUE(subq_15.user) OVER (
- PARTITION BY
- subq_18.user
- , subq_18.ds__day
- , subq_18.mf_internal_uuid
- ORDER BY subq_15.ds__day DESC
- ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
- ) AS user
- , subq_18.mf_internal_uuid AS mf_internal_uuid
- , subq_18.buys AS buys
+ -- Find conversions for user within the range of 7 day
+ SELECT
+ subq_20.ds__day
+ , subq_20.metric_time__day
+ , subq_20.user
+ , subq_20.visit__referrer_id
+ , subq_20.user__home_state_latest
+ , subq_20.buys
+ , subq_20.visits
FROM (
- -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
- SELECT
- subq_14.ds__day
- , subq_14.metric_time__day
- , subq_14.user
- , subq_14.visit__referrer_id
- , subq_14.user__home_state_latest
- , subq_14.visits
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ FIRST_VALUE(subq_16.visits) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visits
+ , FIRST_VALUE(subq_16.visit__referrer_id) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS visit__referrer_id
+ , FIRST_VALUE(subq_16.user__home_state_latest) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user__home_state_latest
+ , FIRST_VALUE(subq_16.ds__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS ds__day
+ , FIRST_VALUE(subq_16.metric_time__day) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS metric_time__day
+ , FIRST_VALUE(subq_16.user) OVER (
+ PARTITION BY
+ subq_19.user
+ , subq_19.ds__day
+ , subq_19.mf_internal_uuid
+ ORDER BY subq_16.ds__day DESC
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+ ) AS user
+ , subq_19.mf_internal_uuid AS mf_internal_uuid
+ , subq_19.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_11.ds__day AS ds__day
- , subq_11.ds__week AS ds__week
- , subq_11.ds__month AS ds__month
- , subq_11.ds__quarter AS ds__quarter
- , subq_11.ds__year AS ds__year
- , subq_11.ds__extract_year AS ds__extract_year
- , subq_11.ds__extract_quarter AS ds__extract_quarter
- , subq_11.ds__extract_month AS ds__extract_month
- , subq_11.ds__extract_day AS ds__extract_day
- , subq_11.ds__extract_dow AS ds__extract_dow
- , subq_11.ds__extract_doy AS ds__extract_doy
- , subq_11.visit__ds__day AS visit__ds__day
- , subq_11.visit__ds__week AS visit__ds__week
- , subq_11.visit__ds__month AS visit__ds__month
- , subq_11.visit__ds__quarter AS visit__ds__quarter
- , subq_11.visit__ds__year AS visit__ds__year
- , subq_11.visit__ds__extract_year AS visit__ds__extract_year
- , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
- , subq_11.visit__ds__extract_month AS visit__ds__extract_month
- , subq_11.visit__ds__extract_day AS visit__ds__extract_day
- , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
- , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
- , subq_11.metric_time__day AS metric_time__day
- , subq_11.metric_time__week AS metric_time__week
- , subq_11.metric_time__month AS metric_time__month
- , subq_11.metric_time__quarter AS metric_time__quarter
- , subq_11.metric_time__year AS metric_time__year
- , subq_11.metric_time__extract_year AS metric_time__extract_year
- , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
- , subq_11.metric_time__extract_month AS metric_time__extract_month
- , subq_11.metric_time__extract_day AS metric_time__extract_day
- , subq_11.metric_time__extract_dow AS metric_time__extract_dow
- , subq_11.metric_time__extract_doy AS metric_time__extract_doy
- , subq_11.user AS user
- , subq_11.session AS session
- , subq_11.visit__user AS visit__user
- , subq_11.visit__session AS visit__session
- , subq_11.referrer_id AS referrer_id
- , subq_11.visit__referrer_id AS visit__referrer_id
- , subq_13.home_state_latest AS user__home_state_latest
- , subq_11.visits AS visits
- , subq_11.visitors AS visitors
+ subq_15.ds__day
+ , subq_15.metric_time__day
+ , subq_15.user
+ , subq_15.visit__referrer_id
+ , subq_15.user__home_state_latest
+ , subq_15.visits
FROM (
- -- Metric Time Dimension 'ds'
- SELECT
- subq_10.ds__day
- , subq_10.ds__week
- , subq_10.ds__month
- , subq_10.ds__quarter
- , subq_10.ds__year
- , subq_10.ds__extract_year
- , subq_10.ds__extract_quarter
- , subq_10.ds__extract_month
- , subq_10.ds__extract_day
- , subq_10.ds__extract_dow
- , subq_10.ds__extract_doy
- , subq_10.visit__ds__day
- , subq_10.visit__ds__week
- , subq_10.visit__ds__month
- , subq_10.visit__ds__quarter
- , subq_10.visit__ds__year
- , subq_10.visit__ds__extract_year
- , subq_10.visit__ds__extract_quarter
- , subq_10.visit__ds__extract_month
- , subq_10.visit__ds__extract_day
- , subq_10.visit__ds__extract_dow
- , subq_10.visit__ds__extract_doy
- , subq_10.ds__day AS metric_time__day
- , subq_10.ds__week AS metric_time__week
- , subq_10.ds__month AS metric_time__month
- , subq_10.ds__quarter AS metric_time__quarter
- , subq_10.ds__year AS metric_time__year
- , subq_10.ds__extract_year AS metric_time__extract_year
- , subq_10.ds__extract_quarter AS metric_time__extract_quarter
- , subq_10.ds__extract_month AS metric_time__extract_month
- , subq_10.ds__extract_day AS metric_time__extract_day
- , subq_10.ds__extract_dow AS metric_time__extract_dow
- , subq_10.ds__extract_doy AS metric_time__extract_doy
- , subq_10.user
- , subq_10.session
- , subq_10.visit__user
- , subq_10.visit__session
- , subq_10.referrer_id
- , subq_10.visit__referrer_id
- , subq_10.visits
- , subq_10.visitors
- FROM (
- -- Read Elements From Semantic Model 'visits_source'
- SELECT
- 1 AS visits
- , visits_source_src_28000.user_id AS visitors
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
- , visits_source_src_28000.referrer_id
- , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
- , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
- , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
- , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
- , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
- , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
- , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
- , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
- , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
- , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
- , visits_source_src_28000.referrer_id AS visit__referrer_id
- , visits_source_src_28000.user_id AS user
- , visits_source_src_28000.session_id AS session
- , visits_source_src_28000.user_id AS visit__user
- , visits_source_src_28000.session_id AS visit__session
- FROM ***************************.fct_visits visits_source_src_28000
- ) subq_10
- ) subq_11
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
+ -- Constrain Output with WHERE
SELECT
- subq_12.user
- , subq_12.home_state_latest
+ subq_14.ds__day
+ , subq_14.ds__week
+ , subq_14.ds__month
+ , subq_14.ds__quarter
+ , subq_14.ds__year
+ , subq_14.ds__extract_year
+ , subq_14.ds__extract_quarter
+ , subq_14.ds__extract_month
+ , subq_14.ds__extract_day
+ , subq_14.ds__extract_dow
+ , subq_14.ds__extract_doy
+ , subq_14.visit__ds__day
+ , subq_14.visit__ds__week
+ , subq_14.visit__ds__month
+ , subq_14.visit__ds__quarter
+ , subq_14.visit__ds__year
+ , subq_14.visit__ds__extract_year
+ , subq_14.visit__ds__extract_quarter
+ , subq_14.visit__ds__extract_month
+ , subq_14.visit__ds__extract_day
+ , subq_14.visit__ds__extract_dow
+ , subq_14.visit__ds__extract_doy
+ , subq_14.metric_time__day
+ , subq_14.metric_time__week
+ , subq_14.metric_time__month
+ , subq_14.metric_time__quarter
+ , subq_14.metric_time__year
+ , subq_14.metric_time__extract_year
+ , subq_14.metric_time__extract_quarter
+ , subq_14.metric_time__extract_month
+ , subq_14.metric_time__extract_day
+ , subq_14.metric_time__extract_dow
+ , subq_14.metric_time__extract_doy
+ , subq_14.user
+ , subq_14.session
+ , subq_14.visit__user
+ , subq_14.visit__session
+ , subq_14.referrer_id
+ , subq_14.visit__referrer_id
+ , subq_14.user__home_state_latest
+ , subq_14.visits
+ , subq_14.visitors
FROM (
- -- Read Elements From Semantic Model 'users_latest'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
- ) subq_12
- ) subq_13
- ON
- subq_11.user = subq_13.user
- ) subq_14
- ) subq_15
- INNER JOIN (
- -- Add column with generated UUID
- SELECT
- subq_17.ds__day
- , subq_17.ds__week
- , subq_17.ds__month
- , subq_17.ds__quarter
- , subq_17.ds__year
- , subq_17.ds__extract_year
- , subq_17.ds__extract_quarter
- , subq_17.ds__extract_month
- , subq_17.ds__extract_day
- , subq_17.ds__extract_dow
- , subq_17.ds__extract_doy
- , subq_17.buy__ds__day
- , subq_17.buy__ds__week
- , subq_17.buy__ds__month
- , subq_17.buy__ds__quarter
- , subq_17.buy__ds__year
- , subq_17.buy__ds__extract_year
- , subq_17.buy__ds__extract_quarter
- , subq_17.buy__ds__extract_month
- , subq_17.buy__ds__extract_day
- , subq_17.buy__ds__extract_dow
- , subq_17.buy__ds__extract_doy
- , subq_17.metric_time__day
- , subq_17.metric_time__week
- , subq_17.metric_time__month
- , subq_17.metric_time__quarter
- , subq_17.metric_time__year
- , subq_17.metric_time__extract_year
- , subq_17.metric_time__extract_quarter
- , subq_17.metric_time__extract_month
- , subq_17.metric_time__extract_day
- , subq_17.metric_time__extract_dow
- , subq_17.metric_time__extract_doy
- , subq_17.user
- , subq_17.session_id
- , subq_17.buy__user
- , subq_17.buy__session_id
- , subq_17.buys
- , subq_17.buyers
- , uuid() AS mf_internal_uuid
- FROM (
- -- Metric Time Dimension 'ds'
+ subq_11.ds__day AS ds__day
+ , subq_11.ds__week AS ds__week
+ , subq_11.ds__month AS ds__month
+ , subq_11.ds__quarter AS ds__quarter
+ , subq_11.ds__year AS ds__year
+ , subq_11.ds__extract_year AS ds__extract_year
+ , subq_11.ds__extract_quarter AS ds__extract_quarter
+ , subq_11.ds__extract_month AS ds__extract_month
+ , subq_11.ds__extract_day AS ds__extract_day
+ , subq_11.ds__extract_dow AS ds__extract_dow
+ , subq_11.ds__extract_doy AS ds__extract_doy
+ , subq_11.visit__ds__day AS visit__ds__day
+ , subq_11.visit__ds__week AS visit__ds__week
+ , subq_11.visit__ds__month AS visit__ds__month
+ , subq_11.visit__ds__quarter AS visit__ds__quarter
+ , subq_11.visit__ds__year AS visit__ds__year
+ , subq_11.visit__ds__extract_year AS visit__ds__extract_year
+ , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter
+ , subq_11.visit__ds__extract_month AS visit__ds__extract_month
+ , subq_11.visit__ds__extract_day AS visit__ds__extract_day
+ , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow
+ , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy
+ , subq_11.metric_time__day AS metric_time__day
+ , subq_11.metric_time__week AS metric_time__week
+ , subq_11.metric_time__month AS metric_time__month
+ , subq_11.metric_time__quarter AS metric_time__quarter
+ , subq_11.metric_time__year AS metric_time__year
+ , subq_11.metric_time__extract_year AS metric_time__extract_year
+ , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_11.metric_time__extract_month AS metric_time__extract_month
+ , subq_11.metric_time__extract_day AS metric_time__extract_day
+ , subq_11.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_11.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_11.user AS user
+ , subq_11.session AS session
+ , subq_11.visit__user AS visit__user
+ , subq_11.visit__session AS visit__session
+ , subq_11.referrer_id AS referrer_id
+ , subq_11.visit__referrer_id AS visit__referrer_id
+ , subq_13.home_state_latest AS user__home_state_latest
+ , subq_11.visits AS visits
+ , subq_11.visitors AS visitors
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_10.ds__day
+ , subq_10.ds__week
+ , subq_10.ds__month
+ , subq_10.ds__quarter
+ , subq_10.ds__year
+ , subq_10.ds__extract_year
+ , subq_10.ds__extract_quarter
+ , subq_10.ds__extract_month
+ , subq_10.ds__extract_day
+ , subq_10.ds__extract_dow
+ , subq_10.ds__extract_doy
+ , subq_10.visit__ds__day
+ , subq_10.visit__ds__week
+ , subq_10.visit__ds__month
+ , subq_10.visit__ds__quarter
+ , subq_10.visit__ds__year
+ , subq_10.visit__ds__extract_year
+ , subq_10.visit__ds__extract_quarter
+ , subq_10.visit__ds__extract_month
+ , subq_10.visit__ds__extract_day
+ , subq_10.visit__ds__extract_dow
+ , subq_10.visit__ds__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.user
+ , subq_10.session
+ , subq_10.visit__user
+ , subq_10.visit__session
+ , subq_10.referrer_id
+ , subq_10.visit__referrer_id
+ , subq_10.visits
+ , subq_10.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_28000.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy
+ , visits_source_src_28000.referrer_id
+ , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy
+ , visits_source_src_28000.referrer_id AS visit__referrer_id
+ , visits_source_src_28000.user_id AS user
+ , visits_source_src_28000.session_id AS session
+ , visits_source_src_28000.user_id AS visit__user
+ , visits_source_src_28000.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_28000
+ ) subq_10
+ ) subq_11
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_12.user
+ , subq_12.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_12
+ ) subq_13
+ ON
+ subq_11.user = subq_13.user
+ ) subq_14
+ WHERE visit__referrer_id = '123456'
+ ) subq_15
+ ) subq_16
+ INNER JOIN (
+ -- Add column with generated UUID
SELECT
- subq_16.ds__day
- , subq_16.ds__week
- , subq_16.ds__month
- , subq_16.ds__quarter
- , subq_16.ds__year
- , subq_16.ds__extract_year
- , subq_16.ds__extract_quarter
- , subq_16.ds__extract_month
- , subq_16.ds__extract_day
- , subq_16.ds__extract_dow
- , subq_16.ds__extract_doy
- , subq_16.buy__ds__day
- , subq_16.buy__ds__week
- , subq_16.buy__ds__month
- , subq_16.buy__ds__quarter
- , subq_16.buy__ds__year
- , subq_16.buy__ds__extract_year
- , subq_16.buy__ds__extract_quarter
- , subq_16.buy__ds__extract_month
- , subq_16.buy__ds__extract_day
- , subq_16.buy__ds__extract_dow
- , subq_16.buy__ds__extract_doy
- , subq_16.ds__day AS metric_time__day
- , subq_16.ds__week AS metric_time__week
- , subq_16.ds__month AS metric_time__month
- , subq_16.ds__quarter AS metric_time__quarter
- , subq_16.ds__year AS metric_time__year
- , subq_16.ds__extract_year AS metric_time__extract_year
- , subq_16.ds__extract_quarter AS metric_time__extract_quarter
- , subq_16.ds__extract_month AS metric_time__extract_month
- , subq_16.ds__extract_day AS metric_time__extract_day
- , subq_16.ds__extract_dow AS metric_time__extract_dow
- , subq_16.ds__extract_doy AS metric_time__extract_doy
- , subq_16.user
- , subq_16.session_id
- , subq_16.buy__user
- , subq_16.buy__session_id
- , subq_16.buys
- , subq_16.buyers
+ subq_18.ds__day
+ , subq_18.ds__week
+ , subq_18.ds__month
+ , subq_18.ds__quarter
+ , subq_18.ds__year
+ , subq_18.ds__extract_year
+ , subq_18.ds__extract_quarter
+ , subq_18.ds__extract_month
+ , subq_18.ds__extract_day
+ , subq_18.ds__extract_dow
+ , subq_18.ds__extract_doy
+ , subq_18.buy__ds__day
+ , subq_18.buy__ds__week
+ , subq_18.buy__ds__month
+ , subq_18.buy__ds__quarter
+ , subq_18.buy__ds__year
+ , subq_18.buy__ds__extract_year
+ , subq_18.buy__ds__extract_quarter
+ , subq_18.buy__ds__extract_month
+ , subq_18.buy__ds__extract_day
+ , subq_18.buy__ds__extract_dow
+ , subq_18.buy__ds__extract_doy
+ , subq_18.metric_time__day
+ , subq_18.metric_time__week
+ , subq_18.metric_time__month
+ , subq_18.metric_time__quarter
+ , subq_18.metric_time__year
+ , subq_18.metric_time__extract_year
+ , subq_18.metric_time__extract_quarter
+ , subq_18.metric_time__extract_month
+ , subq_18.metric_time__extract_day
+ , subq_18.metric_time__extract_dow
+ , subq_18.metric_time__extract_doy
+ , subq_18.user
+ , subq_18.session_id
+ , subq_18.buy__user
+ , subq_18.buy__session_id
+ , subq_18.buys
+ , subq_18.buyers
+ , uuid() AS mf_internal_uuid
FROM (
- -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
SELECT
- 1 AS buys
- , buys_source_src_28000.user_id AS buyers
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM buys_source_src_28000.ds) AS ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
- , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
- , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
- , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
- , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
- , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
- , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
- , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
- , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
- , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
- , EXTRACT(DAY_OF_WEEK FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
- , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
- , buys_source_src_28000.user_id AS user
- , buys_source_src_28000.session_id
- , buys_source_src_28000.user_id AS buy__user
- , buys_source_src_28000.session_id AS buy__session_id
- FROM ***************************.fct_buys buys_source_src_28000
- ) subq_16
- ) subq_17
- ) subq_18
- ON
- (
- subq_15.user = subq_18.user
- ) AND (
+ subq_17.ds__day
+ , subq_17.ds__week
+ , subq_17.ds__month
+ , subq_17.ds__quarter
+ , subq_17.ds__year
+ , subq_17.ds__extract_year
+ , subq_17.ds__extract_quarter
+ , subq_17.ds__extract_month
+ , subq_17.ds__extract_day
+ , subq_17.ds__extract_dow
+ , subq_17.ds__extract_doy
+ , subq_17.buy__ds__day
+ , subq_17.buy__ds__week
+ , subq_17.buy__ds__month
+ , subq_17.buy__ds__quarter
+ , subq_17.buy__ds__year
+ , subq_17.buy__ds__extract_year
+ , subq_17.buy__ds__extract_quarter
+ , subq_17.buy__ds__extract_month
+ , subq_17.buy__ds__extract_day
+ , subq_17.buy__ds__extract_dow
+ , subq_17.buy__ds__extract_doy
+ , subq_17.ds__day AS metric_time__day
+ , subq_17.ds__week AS metric_time__week
+ , subq_17.ds__month AS metric_time__month
+ , subq_17.ds__quarter AS metric_time__quarter
+ , subq_17.ds__year AS metric_time__year
+ , subq_17.ds__extract_year AS metric_time__extract_year
+ , subq_17.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_17.ds__extract_month AS metric_time__extract_month
+ , subq_17.ds__extract_day AS metric_time__extract_day
+ , subq_17.ds__extract_dow AS metric_time__extract_dow
+ , subq_17.ds__extract_doy AS metric_time__extract_doy
+ , subq_17.user
+ , subq_17.session_id
+ , subq_17.buy__user
+ , subq_17.buy__session_id
+ , subq_17.buys
+ , subq_17.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_28000.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_28000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_28000.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy
+ , buys_source_src_28000.user_id AS user
+ , buys_source_src_28000.session_id
+ , buys_source_src_28000.user_id AS buy__user
+ , buys_source_src_28000.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_28000
+ ) subq_17
+ ) subq_18
+ ) subq_19
+ ON
(
- subq_15.ds__day <= subq_18.ds__day
+ subq_16.user = subq_19.user
) AND (
- subq_15.ds__day > DATE_ADD('day', -7, subq_18.ds__day)
+ (
+ subq_16.ds__day <= subq_19.ds__day
+ ) AND (
+ subq_16.ds__day > DATE_ADD('day', -7, subq_19.ds__day)
+ )
)
- )
- ) subq_19
- ) subq_20
- ) subq_21
- LEFT OUTER JOIN (
- -- Pass Only Elements: ['home_state_latest', 'user']
- SELECT
- subq_22.user
- , subq_22.home_state_latest
- FROM (
- -- Read Elements From Semantic Model 'users_latest'
- SELECT
- DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
- , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest
- , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
- , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
- , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
- , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
- , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
- , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
- , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
- , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
- , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
- , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
- , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , users_latest_src_28000.user_id AS user
- FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_20
+ ) subq_21
) subq_22
- ) subq_23
- ON
- subq_21.user = subq_23.user
- ) subq_24
- ) subq_25
- GROUP BY
- subq_25.metric_time__day
- , subq_25.user__home_state_latest
- ) subq_26
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['home_state_latest', 'user']
+ SELECT
+ subq_23.user
+ , subq_23.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , users_latest_src_28000.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_28000
+ ) subq_23
+ ) subq_24
+ ON
+ subq_22.user = subq_24.user
+ ) subq_25
+ ) subq_26
+ GROUP BY
+ subq_26.metric_time__day
+ , subq_26.user__home_state_latest
+ ) subq_27
+ ) subq_28
ON
(
- subq_9.user__home_state_latest = subq_26.user__home_state_latest
+ subq_9.user__home_state_latest = subq_28.user__home_state_latest
) AND (
- subq_9.metric_time__day = subq_26.metric_time__day
+ subq_9.metric_time__day = subq_28.metric_time__day
)
GROUP BY
- COALESCE(subq_9.metric_time__day, subq_26.metric_time__day)
- , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest)
-) subq_27
+ COALESCE(subq_9.metric_time__day, subq_28.metric_time__day)
+ , COALESCE(subq_9.user__home_state_latest, subq_28.user__home_state_latest)
+) subq_29
diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_query_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_query_filters__plan0_optimized.sql
index 8c837d9664..875eb4b3f4 100644
--- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_query_filters__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_query_filters__plan0_optimized.sql
@@ -6,10 +6,10 @@ SELECT
FROM (
-- Combine Aggregated Outputs
SELECT
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day) AS metric_time__day
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest) AS user__home_state_latest
- , MAX(subq_37.visits) AS visits
- , MAX(subq_54.buys) AS buys
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day) AS metric_time__day
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest) AS user__home_state_latest
+ , MAX(subq_39.visits) AS visits
+ , MAX(subq_58.buys) AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'metric_time__day']
@@ -22,10 +22,10 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['visits', 'user__home_state_latest', 'visit__referrer_id', 'metric_time__day']
SELECT
- subq_30.metric_time__day AS metric_time__day
- , subq_30.visit__referrer_id AS visit__referrer_id
+ subq_32.metric_time__day AS metric_time__day
+ , subq_32.visit__referrer_id AS visit__referrer_id
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_30.visits AS visits
+ , subq_32.visits AS visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
@@ -36,104 +36,116 @@ FROM (
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
- ) subq_30
+ ) subq_32
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_30.user = users_latest_src_28000.user_id
- ) subq_34
+ subq_32.user = users_latest_src_28000.user_id
+ ) subq_36
WHERE visit__referrer_id = '123456'
GROUP BY
metric_time__day
, user__home_state_latest
- ) subq_37
+ ) subq_39
FULL OUTER JOIN (
-- Join Standard Outputs
-- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
-- Aggregate Measures
+ -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day']
SELECT
- subq_47.metric_time__day AS metric_time__day
+ subq_50.metric_time__day AS metric_time__day
, users_latest_src_28000.home_state_latest AS user__home_state_latest
- , SUM(subq_47.buys) AS buys
+ , SUM(subq_50.buys) AS buys
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
- FIRST_VALUE(subq_43.visits) OVER (
+ FIRST_VALUE(subq_46.visits) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
- , FIRST_VALUE(subq_43.visit__referrer_id) OVER (
+ , FIRST_VALUE(subq_46.visit__referrer_id) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
- , FIRST_VALUE(subq_43.user__home_state_latest) OVER (
+ , FIRST_VALUE(subq_46.user__home_state_latest) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user__home_state_latest
- , FIRST_VALUE(subq_43.ds__day) OVER (
+ , FIRST_VALUE(subq_46.ds__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
- , FIRST_VALUE(subq_43.metric_time__day) OVER (
+ , FIRST_VALUE(subq_46.metric_time__day) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
- , FIRST_VALUE(subq_43.user) OVER (
+ , FIRST_VALUE(subq_46.user) OVER (
PARTITION BY
- subq_46.user
- , subq_46.ds__day
- , subq_46.mf_internal_uuid
- ORDER BY subq_43.ds__day DESC
+ subq_49.user
+ , subq_49.ds__day
+ , subq_49.mf_internal_uuid
+ ORDER BY subq_46.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
- , subq_46.mf_internal_uuid AS mf_internal_uuid
- , subq_46.buys AS buys
+ , subq_49.mf_internal_uuid AS mf_internal_uuid
+ , subq_49.buys AS buys
FROM (
- -- Join Standard Outputs
+ -- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user']
SELECT
- subq_39.ds__day AS ds__day
- , subq_39.metric_time__day AS metric_time__day
- , subq_39.user AS user
- , subq_39.visit__referrer_id AS visit__referrer_id
- , users_latest_src_28000.home_state_latest AS user__home_state_latest
- , subq_39.visits AS visits
+ ds__day
+ , metric_time__day
+ , subq_44.user
+ , visit__referrer_id
+ , user__home_state_latest
+ , visits
FROM (
- -- Read Elements From Semantic Model 'visits_source'
- -- Metric Time Dimension 'ds'
+ -- Join Standard Outputs
SELECT
- DATE_TRUNC('day', ds) AS ds__day
- , DATE_TRUNC('day', ds) 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_39
- LEFT OUTER JOIN
- ***************************.dim_users_latest users_latest_src_28000
- ON
- subq_39.user = users_latest_src_28000.user_id
- ) subq_43
+ subq_41.ds__day AS ds__day
+ , subq_41.metric_time__day AS metric_time__day
+ , subq_41.user AS user
+ , subq_41.visit__referrer_id AS visit__referrer_id
+ , users_latest_src_28000.home_state_latest AS user__home_state_latest
+ , subq_41.visits AS visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) 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_41
+ LEFT OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_28000
+ ON
+ subq_41.user = users_latest_src_28000.user_id
+ ) subq_44
+ WHERE visit__referrer_id = '123456'
+ ) subq_46
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
@@ -144,33 +156,33 @@ FROM (
, 1 AS buys
, uuid() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
- ) subq_46
+ ) subq_49
ON
(
- subq_43.user = subq_46.user
+ subq_46.user = subq_49.user
) AND (
(
- subq_43.ds__day <= subq_46.ds__day
+ subq_46.ds__day <= subq_49.ds__day
) AND (
- subq_43.ds__day > DATE_ADD('day', -7, subq_46.ds__day)
+ subq_46.ds__day > DATE_ADD('day', -7, subq_49.ds__day)
)
)
- ) subq_47
+ ) subq_50
LEFT OUTER JOIN
***************************.dim_users_latest users_latest_src_28000
ON
- subq_47.user = users_latest_src_28000.user_id
+ subq_50.user = users_latest_src_28000.user_id
GROUP BY
- subq_47.metric_time__day
+ subq_50.metric_time__day
, users_latest_src_28000.home_state_latest
- ) subq_54
+ ) subq_58
ON
(
- subq_37.user__home_state_latest = subq_54.user__home_state_latest
+ subq_39.user__home_state_latest = subq_58.user__home_state_latest
) AND (
- subq_37.metric_time__day = subq_54.metric_time__day
+ subq_39.metric_time__day = subq_58.metric_time__day
)
GROUP BY
- COALESCE(subq_37.metric_time__day, subq_54.metric_time__day)
- , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest)
-) subq_55
+ COALESCE(subq_39.metric_time__day, subq_58.metric_time__day)
+ , COALESCE(subq_39.user__home_state_latest, subq_58.user__home_state_latest)
+) subq_59