From 2018b8d26dcc6d106be274d3878e56cfe01b2438 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Wed, 18 Dec 2024 10:27:15 -0800 Subject: [PATCH] Update snapshots for other SQL engines --- ...and_fill_nulls_with_0__plan0_optimized.sql | 19 +++++++++----- ...and_fill_nulls_with_0__plan0_optimized.sql | 19 +++++++++----- ...and_fill_nulls_with_0__plan0_optimized.sql | 19 +++++++++----- ...and_fill_nulls_with_0__plan0_optimized.sql | 19 +++++++++----- ...and_fill_nulls_with_0__plan0_optimized.sql | 19 +++++++++----- ...and_fill_nulls_with_0__plan0_optimized.sql | 19 +++++++++----- ...w_and_offset_to_grain__plan0_optimized.sql | 19 +++++++++----- ...grain_and_granularity__plan0_optimized.sql | 22 +++++++++++----- ...nstraint_not_selected__plan0_optimized.sql | 21 ++++++++++----- .../test_nested_offsets__plan0_optimized.sql | 21 ++++++++++----- ..._with_time_constraint__plan0_optimized.sql | 23 ++++++++++------ ...with_where_constraint__plan0_optimized.sql | 21 ++++++++++----- ...w_and_offset_to_grain__plan0_optimized.sql | 23 ++++++++++------ ...grain_and_granularity__plan0_optimized.sql | 26 ++++++++++++------- ...nstraint_not_selected__plan0_optimized.sql | 23 ++++++++++------ .../test_nested_offsets__plan0_optimized.sql | 23 ++++++++++------ ..._with_time_constraint__plan0_optimized.sql | 25 +++++++++++------- ...with_where_constraint__plan0_optimized.sql | 23 ++++++++++------ ...w_and_offset_to_grain__plan0_optimized.sql | 23 ++++++++++------ ...grain_and_granularity__plan0_optimized.sql | 26 ++++++++++++------- ...nstraint_not_selected__plan0_optimized.sql | 23 ++++++++++------ .../test_nested_offsets__plan0_optimized.sql | 23 ++++++++++------ ..._with_time_constraint__plan0_optimized.sql | 25 +++++++++++------- ...with_where_constraint__plan0_optimized.sql | 23 ++++++++++------ ...w_and_offset_to_grain__plan0_optimized.sql | 23 ++++++++++------ ...grain_and_granularity__plan0_optimized.sql | 26 ++++++++++++------- ...nstraint_not_selected__plan0_optimized.sql | 23 ++++++++++------ .../test_nested_offsets__plan0_optimized.sql | 23 ++++++++++------ ..._with_time_constraint__plan0_optimized.sql | 25 +++++++++++------- ...with_where_constraint__plan0_optimized.sql | 23 ++++++++++------ ...w_and_offset_to_grain__plan0_optimized.sql | 23 ++++++++++------ ...grain_and_granularity__plan0_optimized.sql | 26 ++++++++++++------- ...nstraint_not_selected__plan0_optimized.sql | 23 ++++++++++------ .../test_nested_offsets__plan0_optimized.sql | 23 ++++++++++------ ..._with_time_constraint__plan0_optimized.sql | 25 +++++++++++------- ...with_where_constraint__plan0_optimized.sql | 23 ++++++++++------ ...w_and_offset_to_grain__plan0_optimized.sql | 23 ++++++++++------ ...grain_and_granularity__plan0_optimized.sql | 26 ++++++++++++------- ...nstraint_not_selected__plan0_optimized.sql | 23 ++++++++++------ .../test_nested_offsets__plan0_optimized.sql | 23 ++++++++++------ ..._with_time_constraint__plan0_optimized.sql | 25 +++++++++++------- ...with_where_constraint__plan0_optimized.sql | 23 ++++++++++------ ..._for_one_input_metric__plan0_optimized.sql | 19 +++++++++----- ..._for_one_input_metric__plan0_optimized.sql | 21 ++++++++++----- ..._for_one_input_metric__plan0_optimized.sql | 21 ++++++++++----- ..._for_one_input_metric__plan0_optimized.sql | 21 ++++++++++----- ..._for_one_input_metric__plan0_optimized.sql | 21 ++++++++++----- ..._for_one_input_metric__plan0_optimized.sql | 21 ++++++++++----- ...ic_predicate_pushdown__plan0_optimized.sql | 25 +++++++++++------- ...ic_predicate_pushdown__plan0_optimized.sql | 25 +++++++++++------- ...ic_predicate_pushdown__plan0_optimized.sql | 25 +++++++++++------- ...ic_predicate_pushdown__plan0_optimized.sql | 25 +++++++++++------- ...ic_predicate_pushdown__plan0_optimized.sql | 25 +++++++++++------- ...ic_predicate_pushdown__plan0_optimized.sql | 25 +++++++++++------- 54 files changed, 807 insertions(+), 423 deletions(-) diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index 04e97e0af..d337455f1 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql @@ -15,6 +15,13 @@ WITH sma_28019_cte AS ( FROM ***************************.fct_visits visits_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , CAST(buys AS FLOAT64) / CAST(NULLIF(visits, 0) AS FLOAT64) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 @@ -27,9 +34,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_26.visits AS visits - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28019 -- Pass Only Elements: ['visits', 'metric_time__day'] @@ -42,14 +49,14 @@ FROM ( metric_time__day ) subq_26 ON - time_spine_src_28006.ds = subq_26.metric_time__day + rss_28018_cte.ds__day = subq_26.metric_time__day ) subq_30 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_39.buys AS buys - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -113,7 +120,7 @@ FROM ( metric_time__day ) subq_39 ON - time_spine_src_28006.ds = subq_39.metric_time__day + rss_28018_cte.ds__day = subq_39.metric_time__day ) subq_43 ON subq_30.metric_time__day = subq_43.metric_time__day diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index 388b9302b..09a99150a 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql @@ -15,6 +15,13 @@ WITH sma_28019_cte AS ( FROM ***************************.fct_visits visits_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , CAST(buys AS DOUBLE) / CAST(NULLIF(visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 @@ -27,9 +34,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_26.visits AS visits - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28019 -- Pass Only Elements: ['visits', 'metric_time__day'] @@ -42,14 +49,14 @@ FROM ( metric_time__day ) subq_26 ON - time_spine_src_28006.ds = subq_26.metric_time__day + rss_28018_cte.ds__day = subq_26.metric_time__day ) subq_30 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_39.buys AS buys - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -113,7 +120,7 @@ FROM ( metric_time__day ) subq_39 ON - time_spine_src_28006.ds = subq_39.metric_time__day + rss_28018_cte.ds__day = subq_39.metric_time__day ) subq_43 ON subq_30.metric_time__day = subq_43.metric_time__day diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index cd6c238dc..a89d4f576 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql @@ -15,6 +15,13 @@ WITH sma_28019_cte AS ( FROM ***************************.fct_visits visits_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , CAST(buys AS DOUBLE PRECISION) / CAST(NULLIF(visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 @@ -27,9 +34,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_26.visits AS visits - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28019 -- Pass Only Elements: ['visits', 'metric_time__day'] @@ -42,14 +49,14 @@ FROM ( metric_time__day ) subq_26 ON - time_spine_src_28006.ds = subq_26.metric_time__day + rss_28018_cte.ds__day = subq_26.metric_time__day ) subq_30 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_39.buys AS buys - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -113,7 +120,7 @@ FROM ( metric_time__day ) subq_39 ON - time_spine_src_28006.ds = subq_39.metric_time__day + rss_28018_cte.ds__day = subq_39.metric_time__day ) subq_43 ON subq_30.metric_time__day = subq_43.metric_time__day diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index b7de22a30..2a00c0c43 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql @@ -15,6 +15,13 @@ WITH sma_28019_cte AS ( FROM ***************************.fct_visits visits_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , CAST(buys AS DOUBLE PRECISION) / CAST(NULLIF(visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 @@ -27,9 +34,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_26.visits AS visits - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28019 -- Pass Only Elements: ['visits', 'metric_time__day'] @@ -42,14 +49,14 @@ FROM ( metric_time__day ) subq_26 ON - time_spine_src_28006.ds = subq_26.metric_time__day + rss_28018_cte.ds__day = subq_26.metric_time__day ) subq_30 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_39.buys AS buys - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -113,7 +120,7 @@ FROM ( metric_time__day ) subq_39 ON - time_spine_src_28006.ds = subq_39.metric_time__day + rss_28018_cte.ds__day = subq_39.metric_time__day ) subq_43 ON subq_30.metric_time__day = subq_43.metric_time__day diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index 3e17a6cac..08c910d3d 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql @@ -15,6 +15,13 @@ WITH sma_28019_cte AS ( FROM ***************************.fct_visits visits_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , CAST(buys AS DOUBLE) / CAST(NULLIF(visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 @@ -27,9 +34,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_26.visits AS visits - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28019 -- Pass Only Elements: ['visits', 'metric_time__day'] @@ -42,14 +49,14 @@ FROM ( metric_time__day ) subq_26 ON - time_spine_src_28006.ds = subq_26.metric_time__day + rss_28018_cte.ds__day = subq_26.metric_time__day ) subq_30 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_39.buys AS buys - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -113,7 +120,7 @@ FROM ( metric_time__day ) subq_39 ON - time_spine_src_28006.ds = subq_39.metric_time__day + rss_28018_cte.ds__day = subq_39.metric_time__day ) subq_43 ON subq_30.metric_time__day = subq_43.metric_time__day diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index 9224c66d0..7221a05c1 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql @@ -15,6 +15,13 @@ WITH sma_28019_cte AS ( FROM ***************************.fct_visits visits_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , CAST(buys AS DOUBLE) / CAST(NULLIF(visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 @@ -27,9 +34,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_26.visits AS visits - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28019 -- Pass Only Elements: ['visits', 'metric_time__day'] @@ -42,14 +49,14 @@ FROM ( metric_time__day ) subq_26 ON - time_spine_src_28006.ds = subq_26.metric_time__day + rss_28018_cte.ds__day = subq_26.metric_time__day ) subq_30 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_39.buys AS buys - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -113,7 +120,7 @@ FROM ( metric_time__day ) subq_39 ON - time_spine_src_28006.ds = subq_39.metric_time__day + rss_28018_cte.ds__day = subq_39.metric_time__day ) subq_43 ON subq_30.metric_time__day = subq_43.metric_time__day diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 7ab10e3f9..2484f394e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,13 +34,13 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATETIME_TRUNC(time_spine_src_28006.ds, month) = sma_28009_cte.metric_time__day + DATETIME_TRUNC(rss_28018_cte.ds__day, month) = sma_28009_cte.metric_time__day GROUP BY metric_time__day ) subq_27 @@ -43,13 +50,13 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 month) = sma_28009_cte.metric_time__day + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 1 month) = sma_28009_cte.metric_time__day GROUP BY metric_time__day ) subq_35 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 3b0d975da..a6480c552 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -12,6 +12,14 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + , DATETIME_TRUNC(ds, year) AS ds__year + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__year AS metric_time__year , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,14 +35,14 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, year) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATETIME_TRUNC(time_spine_src_28006.ds, month) = sma_28009_cte.metric_time__day - WHERE DATETIME_TRUNC(time_spine_src_28006.ds, year) = time_spine_src_28006.ds + DATETIME_TRUNC(rss_28018_cte.ds__day, month) = sma_28009_cte.metric_time__day + WHERE rss_28018_cte.ds__year = rss_28018_cte.ds__day GROUP BY metric_time__year ) subq_27 @@ -44,13 +52,13 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, year) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 month) = sma_28009_cte.metric_time__day + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 1 month) = sma_28009_cte.metric_time__day GROUP BY metric_time__year ) subq_35 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 95f6f4f23..d447bef70 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: BigQuery --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -15,10 +22,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_25.booking__is_instant AS booking__is_instant , subq_25.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -31,10 +38,10 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_17.booking__is_instant AS booking__is_instant , SUM(subq_17.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -45,14 +52,14 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_17 ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_17.metric_time__day + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 5 day) = subq_17.metric_time__day GROUP BY metric_time__day , booking__is_instant ) subq_24 ) subq_25 ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_25.metric_time__day + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 2 day) = subq_25.metric_time__day ) subq_29 WHERE booking__is_instant ) subq_31 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets__plan0_optimized.sql index 6af166cd3..3b8f44aff 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets__plan0_optimized.sql @@ -3,15 +3,22 @@ test_filename: test_derived_metric_rendering.py sql_engine: BigQuery --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_23.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -23,9 +30,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_15.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -35,11 +42,11 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_15 ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_15.metric_time__day + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 5 day) = subq_15.metric_time__day GROUP BY metric_time__day ) subq_22 ) subq_23 ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_23.metric_time__day + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 2 day) = subq_23.metric_time__day ) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 0f735319d..cc6167fe4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0_optimized.sql @@ -3,16 +3,23 @@ test_filename: test_derived_metric_rendering.py sql_engine: BigQuery --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -24,9 +31,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -36,12 +43,12 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_16.metric_time__day + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 5 day) = subq_16.metric_time__day GROUP BY metric_time__day ) subq_23 ) subq_24 ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_24.metric_time__day - WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 2 day) = subq_24.metric_time__day + WHERE rss_28018_cte.ds__day BETWEEN '2020-01-12' AND '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 46d542366..84340cf9e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: BigQuery --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -14,9 +21,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -28,9 +35,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -40,13 +47,13 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_16.metric_time__day + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 5 day) = subq_16.metric_time__day GROUP BY metric_time__day ) subq_23 ) subq_24 ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_24.metric_time__day + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 2 day) = subq_24.metric_time__day ) subq_28 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 3c0b65baf..208d1e0e5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,15 +34,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -43,15 +50,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_35 ON subq_27.metric_time__day = subq_35.metric_time__day diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index cb23b153b..355d59fdd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -12,6 +12,14 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + , DATE_TRUNC('year', ds) AS ds__year + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__year AS metric_time__year , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,16 +35,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds + DATE_TRUNC('month', rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day + WHERE rss_28018_cte.ds__year = rss_28018_cte.ds__day GROUP BY - DATE_TRUNC('year', time_spine_src_28006.ds) + rss_28018_cte.ds__year ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -44,15 +52,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('year', time_spine_src_28006.ds) + rss_28018_cte.ds__year ) subq_35 ON subq_27.metric_time__year = subq_35.metric_time__year diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 89bcc32f7..a309d6c48 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: Databricks --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -15,10 +22,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_25.booking__is_instant AS booking__is_instant , subq_25.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -31,10 +38,10 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_17.booking__is_instant AS booking__is_instant , SUM(subq_17.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -45,14 +52,14 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_17 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_17.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_17.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day , subq_17.booking__is_instant ) subq_24 ) subq_25 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_25.metric_time__day + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_25.metric_time__day ) subq_29 WHERE booking__is_instant ) subq_31 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets__plan0_optimized.sql index 9aec36d40..8a71a475c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets__plan0_optimized.sql @@ -3,15 +3,22 @@ test_filename: test_derived_metric_rendering.py sql_engine: Databricks --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_23.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -23,9 +30,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_15.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -35,11 +42,11 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_15 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_15.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_15.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_22 ) subq_23 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_23.metric_time__day + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_23.metric_time__day ) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 837d11c0c..3d8a5abf9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets_with_time_constraint__plan0_optimized.sql @@ -3,16 +3,23 @@ test_filename: test_derived_metric_rendering.py sql_engine: Databricks --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -24,9 +31,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -36,12 +43,12 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_16.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_23 ) subq_24 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day - WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_24.metric_time__day + WHERE rss_28018_cte.ds__day BETWEEN '2020-01-12' AND '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 7f46354fc..6140bc367 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Databricks/test_nested_offsets_with_where_constraint__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: Databricks --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -14,9 +21,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -28,9 +35,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -40,13 +47,13 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_16.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_23 ) subq_24 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_24.metric_time__day ) subq_28 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 3a017678a..a8f86c1b5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,15 +34,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -43,15 +50,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - time_spine_src_28006.ds - MAKE_INTERVAL(months => 1) = sma_28009_cte.metric_time__day + rss_28018_cte.ds__day - MAKE_INTERVAL(months => 1) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_35 ON subq_27.metric_time__day = subq_35.metric_time__day diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index fc91a0d49..eed16fab4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -12,6 +12,14 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + , DATE_TRUNC('year', ds) AS ds__year + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__year AS metric_time__year , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,16 +35,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds + DATE_TRUNC('month', rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day + WHERE rss_28018_cte.ds__year = rss_28018_cte.ds__day GROUP BY - DATE_TRUNC('year', time_spine_src_28006.ds) + rss_28018_cte.ds__year ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -44,15 +52,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - time_spine_src_28006.ds - MAKE_INTERVAL(months => 1) = sma_28009_cte.metric_time__day + rss_28018_cte.ds__day - MAKE_INTERVAL(months => 1) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('year', time_spine_src_28006.ds) + rss_28018_cte.ds__year ) subq_35 ON subq_27.metric_time__year = subq_35.metric_time__year diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index cd6a43d88..c27292f69 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: Postgres --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -15,10 +22,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_25.booking__is_instant AS booking__is_instant , subq_25.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -31,10 +38,10 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_17.booking__is_instant AS booking__is_instant , SUM(subq_17.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -45,14 +52,14 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_17 ON - time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = subq_17.metric_time__day + rss_28018_cte.ds__day - MAKE_INTERVAL(days => 5) = subq_17.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day , subq_17.booking__is_instant ) subq_24 ) subq_25 ON - time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = subq_25.metric_time__day + rss_28018_cte.ds__day - MAKE_INTERVAL(days => 2) = subq_25.metric_time__day ) subq_29 WHERE booking__is_instant ) subq_31 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets__plan0_optimized.sql index 0cf2bf281..ead5c3ff3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets__plan0_optimized.sql @@ -3,15 +3,22 @@ test_filename: test_derived_metric_rendering.py sql_engine: Postgres --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_23.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -23,9 +30,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_15.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -35,11 +42,11 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_15 ON - time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = subq_15.metric_time__day + rss_28018_cte.ds__day - MAKE_INTERVAL(days => 5) = subq_15.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_22 ) subq_23 ON - time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = subq_23.metric_time__day + rss_28018_cte.ds__day - MAKE_INTERVAL(days => 2) = subq_23.metric_time__day ) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 47a6aadd2..fd46b219c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets_with_time_constraint__plan0_optimized.sql @@ -3,16 +3,23 @@ test_filename: test_derived_metric_rendering.py sql_engine: Postgres --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -24,9 +31,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -36,12 +43,12 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = subq_16.metric_time__day + rss_28018_cte.ds__day - MAKE_INTERVAL(days => 5) = subq_16.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_23 ) subq_24 ON - time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = subq_24.metric_time__day - WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' + rss_28018_cte.ds__day - MAKE_INTERVAL(days => 2) = subq_24.metric_time__day + WHERE rss_28018_cte.ds__day BETWEEN '2020-01-12' AND '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 52405830a..b41333666 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Postgres/test_nested_offsets_with_where_constraint__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: Postgres --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -14,9 +21,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -28,9 +35,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -40,13 +47,13 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = subq_16.metric_time__day + rss_28018_cte.ds__day - MAKE_INTERVAL(days => 5) = subq_16.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_23 ) subq_24 ON - time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = subq_24.metric_time__day + rss_28018_cte.ds__day - MAKE_INTERVAL(days => 2) = subq_24.metric_time__day ) subq_28 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 1292c54d7..4959d9f2e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,15 +34,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -43,15 +50,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_35 ON subq_27.metric_time__day = subq_35.metric_time__day diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 6d06b64f1..3e2075160 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -12,6 +12,14 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + , DATE_TRUNC('year', ds) AS ds__year + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__year AS metric_time__year , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,16 +35,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds + DATE_TRUNC('month', rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day + WHERE rss_28018_cte.ds__year = rss_28018_cte.ds__day GROUP BY - DATE_TRUNC('year', time_spine_src_28006.ds) + rss_28018_cte.ds__year ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -44,15 +52,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('year', time_spine_src_28006.ds) + rss_28018_cte.ds__year ) subq_35 ON subq_27.metric_time__year = subq_35.metric_time__year diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index e2a58e966..2db37a954 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: Redshift --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -15,10 +22,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_25.booking__is_instant AS booking__is_instant , subq_25.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -31,10 +38,10 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_17.booking__is_instant AS booking__is_instant , SUM(subq_17.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -45,14 +52,14 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_17 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_17.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_17.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day , subq_17.booking__is_instant ) subq_24 ) subq_25 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_25.metric_time__day + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_25.metric_time__day ) subq_29 WHERE booking__is_instant ) subq_31 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets__plan0_optimized.sql index 78c6b87a9..bc92f162b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets__plan0_optimized.sql @@ -3,15 +3,22 @@ test_filename: test_derived_metric_rendering.py sql_engine: Redshift --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_23.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -23,9 +30,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_15.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -35,11 +42,11 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_15 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_15.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_15.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_22 ) subq_23 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_23.metric_time__day + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_23.metric_time__day ) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets_with_time_constraint__plan0_optimized.sql index abff7fdb5..0a8f2e646 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets_with_time_constraint__plan0_optimized.sql @@ -3,16 +3,23 @@ test_filename: test_derived_metric_rendering.py sql_engine: Redshift --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -24,9 +31,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -36,12 +43,12 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_16.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_23 ) subq_24 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day - WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_24.metric_time__day + WHERE rss_28018_cte.ds__day BETWEEN '2020-01-12' AND '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets_with_where_constraint__plan0_optimized.sql index b75545623..a5aa73f43 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Redshift/test_nested_offsets_with_where_constraint__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: Redshift --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -14,9 +21,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -28,9 +35,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -40,13 +47,13 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_16.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_23 ) subq_24 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_24.metric_time__day ) subq_28 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 4c95cb143..1d48535d3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,15 +34,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -43,15 +50,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_35 ON subq_27.metric_time__day = subq_35.metric_time__day diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 8b847c849..e3b8257ea 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -12,6 +12,14 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + , DATE_TRUNC('year', ds) AS ds__year + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__year AS metric_time__year , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,16 +35,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds + DATE_TRUNC('month', rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day + WHERE rss_28018_cte.ds__year = rss_28018_cte.ds__day GROUP BY - DATE_TRUNC('year', time_spine_src_28006.ds) + rss_28018_cte.ds__year ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -44,15 +52,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('year', time_spine_src_28006.ds) + rss_28018_cte.ds__year ) subq_35 ON subq_27.metric_time__year = subq_35.metric_time__year diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index be9fa2df7..76d14a20c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: Snowflake --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -15,10 +22,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_25.booking__is_instant AS booking__is_instant , subq_25.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -31,10 +38,10 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_17.booking__is_instant AS booking__is_instant , SUM(subq_17.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -45,14 +52,14 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_17 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_17.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_17.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day , subq_17.booking__is_instant ) subq_24 ) subq_25 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_25.metric_time__day + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_25.metric_time__day ) subq_29 WHERE booking__is_instant ) subq_31 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets__plan0_optimized.sql index b21ee2333..8e6206d4a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets__plan0_optimized.sql @@ -3,15 +3,22 @@ test_filename: test_derived_metric_rendering.py sql_engine: Snowflake --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_23.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -23,9 +30,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_15.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -35,11 +42,11 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_15 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_15.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_15.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_22 ) subq_23 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_23.metric_time__day + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_23.metric_time__day ) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 96fb239f1..57fd1ac31 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0_optimized.sql @@ -3,16 +3,23 @@ test_filename: test_derived_metric_rendering.py sql_engine: Snowflake --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -24,9 +31,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -36,12 +43,12 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_16.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_23 ) subq_24 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day - WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_24.metric_time__day + WHERE rss_28018_cte.ds__day BETWEEN '2020-01-12' AND '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 1b0f2830a..253b59aea 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: Snowflake --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -14,9 +21,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -28,9 +35,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -40,13 +47,13 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day + DATEADD(day, -5, rss_28018_cte.ds__day) = subq_16.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_23 ) subq_24 ON - DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day + DATEADD(day, -2, rss_28018_cte.ds__day) = subq_24.metric_time__day ) subq_28 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index f5a5f9b9a..b97539543 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,15 +34,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -43,15 +50,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('month', -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATE_ADD('month', -1, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_35 ON subq_27.metric_time__day = subq_35.metric_time__day diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 0e82437ef..875e4ca7f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -12,6 +12,14 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + , DATE_TRUNC('year', ds) AS ds__year + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__year AS metric_time__year , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior @@ -27,16 +35,16 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds + DATE_TRUNC('month', rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day + WHERE rss_28018_cte.ds__year = rss_28018_cte.ds__day GROUP BY - DATE_TRUNC('year', time_spine_src_28006.ds) + rss_28018_cte.ds__year ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset @@ -44,15 +52,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + rss_28018_cte.ds__year AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('month', -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATE_ADD('month', -1, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('year', time_spine_src_28006.ds) + rss_28018_cte.ds__year ) subq_35 ON subq_27.metric_time__year = subq_35.metric_time__year diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 01dab6b8e..634ea7892 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: Trino --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -15,10 +22,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_25.booking__is_instant AS booking__is_instant , subq_25.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -31,10 +38,10 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_17.booking__is_instant AS booking__is_instant , SUM(subq_17.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -45,14 +52,14 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_17 ON - DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_17.metric_time__day + DATE_ADD('day', -5, rss_28018_cte.ds__day) = subq_17.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day , subq_17.booking__is_instant ) subq_24 ) subq_25 ON - DATE_ADD('day', -2, time_spine_src_28006.ds) = subq_25.metric_time__day + DATE_ADD('day', -2, rss_28018_cte.ds__day) = subq_25.metric_time__day ) subq_29 WHERE booking__is_instant ) subq_31 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets__plan0_optimized.sql index e59300d86..4a84ae80b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets__plan0_optimized.sql @@ -3,15 +3,22 @@ test_filename: test_derived_metric_rendering.py sql_engine: Trino --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_23.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -23,9 +30,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_15.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -35,11 +42,11 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_15 ON - DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_15.metric_time__day + DATE_ADD('day', -5, rss_28018_cte.ds__day) = subq_15.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_22 ) subq_23 ON - DATE_ADD('day', -2, time_spine_src_28006.ds) = subq_23.metric_time__day + DATE_ADD('day', -2, rss_28018_cte.ds__day) = subq_23.metric_time__day ) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql index b3018cd73..d6bf6030d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql @@ -3,16 +3,23 @@ test_filename: test_derived_metric_rendering.py sql_engine: Trino --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -24,9 +31,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -36,12 +43,12 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_16.metric_time__day + DATE_ADD('day', -5, rss_28018_cte.ds__day) = subq_16.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_23 ) subq_24 ON - DATE_ADD('day', -2, time_spine_src_28006.ds) = subq_24.metric_time__day - WHERE time_spine_src_28006.ds BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' + DATE_ADD('day', -2, rss_28018_cte.ds__day) = subq_24.metric_time__day + WHERE rss_28018_cte.ds__day BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 38d6d2753..bb18ead16 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql @@ -3,8 +3,15 @@ test_filename: test_derived_metric_rendering.py sql_engine: Trino --- -- Compute Metrics via Expressions +WITH rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT - metric_time__day + metric_time__day AS metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE @@ -14,9 +21,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_24.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -28,9 +35,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(subq_16.bookings) AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -40,13 +47,13 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 ) subq_16 ON - DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_16.metric_time__day + DATE_ADD('day', -5, rss_28018_cte.ds__day) = subq_16.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_23 ) subq_24 ON - DATE_ADD('day', -2, time_spine_src_28006.ds) = subq_24.metric_time__day + DATE_ADD('day', -2, rss_28018_cte.ds__day) = subq_24.metric_time__day ) subq_28 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' ) subq_29 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index bc4c76ab9..403db7de6 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset @@ -29,9 +36,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_22.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -44,7 +51,7 @@ FROM ( metric_time__day ) subq_22 ON - time_spine_src_28006.ds = subq_22.metric_time__day + rss_28018_cte.ds__day = subq_22.metric_time__day ) subq_26 ) subq_27 FULL OUTER JOIN ( @@ -53,13 +60,13 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day GROUP BY metric_time__day ) subq_35 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index b89168fc0..05ed03750 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset @@ -29,9 +36,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_22.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -44,7 +51,7 @@ FROM ( metric_time__day ) subq_22 ON - time_spine_src_28006.ds = subq_22.metric_time__day + rss_28018_cte.ds__day = subq_22.metric_time__day ) subq_26 ) subq_27 FULL OUTER JOIN ( @@ -53,15 +60,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_35 ON subq_27.metric_time__day = subq_35.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 9cb9ff0f3..17633a2fc 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset @@ -29,9 +36,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_22.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -44,7 +51,7 @@ FROM ( metric_time__day ) subq_22 ON - time_spine_src_28006.ds = subq_22.metric_time__day + rss_28018_cte.ds__day = subq_22.metric_time__day ) subq_26 ) subq_27 FULL OUTER JOIN ( @@ -53,15 +60,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day + rss_28018_cte.ds__day - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_35 ON subq_27.metric_time__day = subq_35.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index a9f252ee2..1fed8fc20 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset @@ -29,9 +36,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_22.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -44,7 +51,7 @@ FROM ( metric_time__day ) subq_22 ON - time_spine_src_28006.ds = subq_22.metric_time__day + rss_28018_cte.ds__day = subq_22.metric_time__day ) subq_26 ) subq_27 FULL OUTER JOIN ( @@ -53,15 +60,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_35 ON subq_27.metric_time__day = subq_35.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 2bf1ecb8e..5b566d299 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset @@ -29,9 +36,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_22.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -44,7 +51,7 @@ FROM ( metric_time__day ) subq_22 ON - time_spine_src_28006.ds = subq_22.metric_time__day + rss_28018_cte.ds__day = subq_22.metric_time__day ) subq_26 ) subq_27 FULL OUTER JOIN ( @@ -53,15 +60,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_35 ON subq_27.metric_time__day = subq_35.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 425dab581..561bc2d1b 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -12,6 +12,13 @@ WITH sma_28009_cte AS ( FROM ***************************.fct_bookings bookings_source_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset @@ -29,9 +36,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_22.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -44,7 +51,7 @@ FROM ( metric_time__day ) subq_22 ON - time_spine_src_28006.ds = subq_22.metric_time__day + rss_28018_cte.ds__day = subq_22.metric_time__day ) subq_26 ) subq_27 FULL OUTER JOIN ( @@ -53,15 +60,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('day', -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATE_ADD('day', -14, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day GROUP BY - time_spine_src_28006.ds + rss_28018_cte.ds__day ) subq_35 ON subq_27.metric_time__day = subq_35.metric_time__day diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 1664f5cfc..7d2250613 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql @@ -27,6 +27,13 @@ WITH sma_28009_cte AS ( FROM ***************************.dim_listings_latest listings_latest_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , listing__country_latest AS listing__country_latest @@ -47,10 +54,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_41.listing__country_latest AS listing__country_latest , subq_41.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -78,7 +85,7 @@ FROM ( , listing__country_latest ) subq_41 ON - time_spine_src_28006.ds = subq_41.metric_time__day + rss_28018_cte.ds__day = subq_41.metric_time__day ) subq_45 ) subq_46 FULL OUTER JOIN ( @@ -90,10 +97,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_57.listing__country_latest AS listing__country_latest , subq_57.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -112,15 +119,15 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day + DATE_SUB(CAST(rss_28018_cte.ds__day AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte @@ -133,7 +140,7 @@ FROM ( , listing__country_latest ) subq_57 ON - time_spine_src_28006.ds = subq_57.metric_time__day + rss_28018_cte.ds__day = subq_57.metric_time__day ) subq_61 ) subq_62 ON diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index d729f4a16..5e97f5b59 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql @@ -27,6 +27,13 @@ WITH sma_28009_cte AS ( FROM ***************************.dim_listings_latest listings_latest_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , listing__country_latest AS listing__country_latest @@ -47,10 +54,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_41.listing__country_latest AS listing__country_latest , subq_41.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -78,7 +85,7 @@ FROM ( , listing__country_latest ) subq_41 ON - time_spine_src_28006.ds = subq_41.metric_time__day + rss_28018_cte.ds__day = subq_41.metric_time__day ) subq_45 ) subq_46 FULL OUTER JOIN ( @@ -90,10 +97,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_57.listing__country_latest AS listing__country_latest , subq_57.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -112,15 +119,15 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte @@ -133,7 +140,7 @@ FROM ( , listing__country_latest ) subq_57 ON - time_spine_src_28006.ds = subq_57.metric_time__day + rss_28018_cte.ds__day = subq_57.metric_time__day ) subq_61 ) subq_62 ON diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 0ae100186..29cfc512f 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql @@ -27,6 +27,13 @@ WITH sma_28009_cte AS ( FROM ***************************.dim_listings_latest listings_latest_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , listing__country_latest AS listing__country_latest @@ -47,10 +54,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_41.listing__country_latest AS listing__country_latest , subq_41.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -78,7 +85,7 @@ FROM ( , listing__country_latest ) subq_41 ON - time_spine_src_28006.ds = subq_41.metric_time__day + rss_28018_cte.ds__day = subq_41.metric_time__day ) subq_45 ) subq_46 FULL OUTER JOIN ( @@ -90,10 +97,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_57.listing__country_latest AS listing__country_latest , subq_57.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -112,15 +119,15 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day + rss_28018_cte.ds__day - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte @@ -133,7 +140,7 @@ FROM ( , listing__country_latest ) subq_57 ON - time_spine_src_28006.ds = subq_57.metric_time__day + rss_28018_cte.ds__day = subq_57.metric_time__day ) subq_61 ) subq_62 ON diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 321d4f55d..1b325d167 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql @@ -27,6 +27,13 @@ WITH sma_28009_cte AS ( FROM ***************************.dim_listings_latest listings_latest_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , listing__country_latest AS listing__country_latest @@ -47,10 +54,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_41.listing__country_latest AS listing__country_latest , subq_41.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -78,7 +85,7 @@ FROM ( , listing__country_latest ) subq_41 ON - time_spine_src_28006.ds = subq_41.metric_time__day + rss_28018_cte.ds__day = subq_41.metric_time__day ) subq_45 ) subq_46 FULL OUTER JOIN ( @@ -90,10 +97,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_57.listing__country_latest AS listing__country_latest , subq_57.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -112,15 +119,15 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte @@ -133,7 +140,7 @@ FROM ( , listing__country_latest ) subq_57 ON - time_spine_src_28006.ds = subq_57.metric_time__day + rss_28018_cte.ds__day = subq_57.metric_time__day ) subq_61 ) subq_62 ON diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index a9bbc330c..b67368ffd 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql @@ -27,6 +27,13 @@ WITH sma_28009_cte AS ( FROM ***************************.dim_listings_latest listings_latest_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , listing__country_latest AS listing__country_latest @@ -47,10 +54,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_41.listing__country_latest AS listing__country_latest , subq_41.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -78,7 +85,7 @@ FROM ( , listing__country_latest ) subq_41 ON - time_spine_src_28006.ds = subq_41.metric_time__day + rss_28018_cte.ds__day = subq_41.metric_time__day ) subq_45 ) subq_46 FULL OUTER JOIN ( @@ -90,10 +97,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_57.listing__country_latest AS listing__country_latest , subq_57.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -112,15 +119,15 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte @@ -133,7 +140,7 @@ FROM ( , listing__country_latest ) subq_57 ON - time_spine_src_28006.ds = subq_57.metric_time__day + rss_28018_cte.ds__day = subq_57.metric_time__day ) subq_61 ) subq_62 ON diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index ff3f3308e..4d398d2a6 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql @@ -27,6 +27,13 @@ WITH sma_28009_cte AS ( FROM ***************************.dim_listings_latest listings_latest_src_28000 ) +, rss_28018_cte AS ( + -- Read From Time Spine 'mf_time_spine' + SELECT + ds AS ds__day + FROM ***************************.mf_time_spine time_spine_src_28006 +) + SELECT metric_time__day AS metric_time__day , listing__country_latest AS listing__country_latest @@ -47,10 +54,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_41.listing__country_latest AS listing__country_latest , subq_41.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -78,7 +85,7 @@ FROM ( , listing__country_latest ) subq_41 ON - time_spine_src_28006.ds = subq_41.metric_time__day + rss_28018_cte.ds__day = subq_41.metric_time__day ) subq_45 ) subq_46 FULL OUTER JOIN ( @@ -90,10 +97,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , subq_57.listing__country_latest AS listing__country_latest , subq_57.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -112,15 +119,15 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - time_spine_src_28006.ds AS metric_time__day + rss_28018_cte.ds__day AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine time_spine_src_28006 + FROM rss_28018_cte rss_28018_cte INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('day', -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + DATE_ADD('day', -14, rss_28018_cte.ds__day) = sma_28009_cte.metric_time__day ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte @@ -133,7 +140,7 @@ FROM ( , listing__country_latest ) subq_57 ON - time_spine_src_28006.ds = subq_57.metric_time__day + rss_28018_cte.ds__day = subq_57.metric_time__day ) subq_61 ) subq_62 ON