From 4cdae619d18d0a6285b157428113754c101082a2 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Fri, 22 Nov 2024 17:00:49 -0800 Subject: [PATCH] Update DuckDB snapshots --- ...timespine_and_fill_nulls_with_0__plan0.sql | 460 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...timespine_and_fill_nulls_with_0__plan0.xml | 588 +++++---- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._metric_with_custom_granularity__plan0.sql | 64 +- ...th_custom_granularity__plan0_optimized.sql | 18 +- ...nularity_filter_not_in_group_by__plan0.sql | 264 ++-- ...ilter_not_in_group_by__plan0_optimized.sql | 20 +- ..._derived_metric_offset_to_grain__dfp_0.xml | 7 +- ...st_derived_metric_offset_window__dfp_0.xml | 7 +- ..._metric_offset_with_granularity__dfp_0.xml | 7 +- ...erived_offset_cumulative_metric__dfp_0.xml | 7 +- ...in_to_time_spine_derived_metric__dfp_0.xml | 17 +- ...join_to_time_spine_with_filters__dfp_0.xml | 13 +- ..._to_time_spine_with_metric_time__dfp_0.xml | 5 + ...erived_metric_with_outer_offset__dfp_0.xml | 12 +- ...ry_have_different_granularities__dfp_0.xml | 7 +- ...ry_have_different_granularities__dfp_0.xml | 9 +- ...set_metric_with_time_constraint__plan0.sql | 258 ++-- ..._with_time_constraint__plan0_optimized.sql | 24 +- ...nth_dimension_and_offset_window__plan0.sql | 60 +- ...ion_and_offset_window__plan0_optimized.sql | 14 +- ...ved_metric_with_offset_to_grain__plan0.sql | 68 +- ..._with_offset_to_grain__plan0_optimized.sql | 30 +- ...offset_to_grain_and_granularity__plan0.sql | 76 +- ...grain_and_granularity__plan0_optimized.sql | 32 +- ...rived_metric_with_offset_window__plan0.sql | 68 +- ...ic_with_offset_window__plan0_optimized.sql | 30 +- ...h_offset_window_and_granularity__plan0.sql | 74 +- ...indow_and_granularity__plan0_optimized.sql | 30 +- ...fset_window_and_offset_to_grain__plan0.sql | 520 ++++---- ...w_and_offset_to_grain__plan0_optimized.sql | 40 +- ...offset_to_grain_and_granularity__plan0.sql | 532 ++++---- ...grain_and_granularity__plan0_optimized.sql | 42 +- ...h_offset_window_and_time_filter__plan0.sql | 266 ++-- ...indow_and_time_filter__plan0_optimized.sql | 30 +- ...erived_offset_cumulative_metric__plan0.sql | 58 +- ...set_cumulative_metric__plan0_optimized.sql | 22 +- ...offset_metric_with_agg_time_dim__plan0.sql | 290 +++-- ...ric_with_agg_time_dim__plan0_optimized.sql | 24 +- ...et_metric_with_one_input_metric__plan0.sql | 58 +- ...with_one_input_metric__plan0_optimized.sql | 14 +- ...d_where_constraint_not_selected__plan0.sql | 126 +- ...nstraint_not_selected__plan0_optimized.sql | 34 +- ...h_offset_multiple_input_metrics__plan0.sql | 274 ++-- ...ultiple_input_metrics__plan0_optimized.sql | 30 +- .../DuckDB/test_nested_offsets__plan0.sql | 100 +- .../test_nested_offsets__plan0_optimized.sql | 26 +- ...ed_offsets_with_time_constraint__plan0.sql | 108 +- ..._with_time_constraint__plan0_optimized.sql | 28 +- ...d_offsets_with_where_constraint__plan0.sql | 106 +- ...with_where_constraint__plan0_optimized.sql | 28 +- ...ry_have_different_granularities__plan0.sql | 264 ++-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 90 +- ...ultiple_granularities__plan0_optimized.sql | 22 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 68 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 30 +- ...ry_have_different_granularities__plan0.sql | 692 +++++----- ...fferent_granularities__plan0_optimized.sql | 28 +- ...w_metric_multiple_granularities__plan0.sql | 350 +++--- ...ultiple_granularities__plan0_optimized.sql | 44 +- ...offset_window_with_agg_time_dim__plan0.sql | 68 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 30 +- ...set_metric_with_time_constraint__plan0.sql | 258 ++-- ..._with_time_constraint__plan0_optimized.sql | 16 +- .../test_cumulative_fill_nulls__plan0.sql | 40 +- ...cumulative_fill_nulls__plan0_optimized.sql | 22 +- ...fill_nulls_for_one_input_metric__plan0.sql | 506 ++++---- ..._for_one_input_metric__plan0_optimized.sql | 42 +- ...ine_with_filter_not_in_group_by__plan0.sql | 54 +- ...ilter_not_in_group_by__plan0_optimized.sql | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 57 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 54 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 54 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 72 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...e_fill_nulls_with_0_metric_time__plan0.sql | 40 +- ...ls_with_0_metric_time__plan0_optimized.sql | 14 +- ..._simple_fill_nulls_with_0_month__plan0.sql | 42 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 18 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- ...ides_metric_default_granularity__plan0.sql | 40 +- ...c_default_granularity__plan0_optimized.sql | 12 +- ...daily_join_to_time_spine_metric__plan0.sql | 40 +- ..._to_time_spine_metric__plan0_optimized.sql | 12 +- ...subdaily_offset_to_grain_metric__plan0.sql | 58 +- ...ffset_to_grain_metric__plan0_optimized.sql | 14 +- ...t_subdaily_offset_window_metric__plan0.sql | 58 +- ..._offset_window_metric__plan0_optimized.sql | 14 +- ...ily_time_constraint_with_metric__plan0.sql | 56 +- ...onstraint_with_metric__plan0_optimized.sql | 19 +- ...spine_metric_predicate_pushdown__dfp_0.xml | 26 +- ...pine_metric_predicate_pushdown__dfpo_0.xml | 34 +- ...ost_agg_join_predicate_pushdown__dfp_0.xml | 26 +- ...st_agg_join_predicate_pushdown__dfpo_0.xml | 34 +- ...ffset_metric_predicate_pushdown__dfp_0.xml | 16 +- ...fset_metric_predicate_pushdown__dfpo_0.xml | 24 +- ...spine_metric_predicate_pushdown__plan0.sql | 1110 +++++++++-------- ...ic_predicate_pushdown__plan0_optimized.sql | 88 +- ..._metric_with_query_time_filters__plan0.sql | 630 +++++----- ...th_query_time_filters__plan0_optimized.sql | 60 +- ...ine_pushdown_filter_application__plan0.sql | 50 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ...e_with_input_measure_constraint__plan0.sql | 47 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 56 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../test_simple_join_to_time_spine__plan0.sql | 40 +- ...le_join_to_time_spine__plan0_optimized.sql | 12 +- ..._join_to_time_spine_with_filter__plan0.sql | 40 +- ...ime_spine_with_filter__plan0_optimized.sql | 14 +- ..._time_spine_with_queried_filter__plan0.sql | 50 +- ...e_with_queried_filter__plan0_optimized.sql | 18 +- 121 files changed, 6495 insertions(+), 4768 deletions(-) diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index f0cde24ff..2c374bed8 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_20.metric_time__day - , CAST(subq_20.buys AS DOUBLE) / CAST(NULLIF(subq_20.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 + subq_22.metric_time__day + , CAST(subq_22.buys AS DOUBLE) / CAST(NULLIF(subq_22.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_19.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_6.visits), 0) AS visits - , COALESCE(MAX(subq_19.buys), 0) AS buys + COALESCE(subq_7.metric_time__day, subq_21.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_7.visits), 0) AS visits + , COALESCE(MAX(subq_21.buys), 0) AS buys FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.visits AS visits FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ds__day AS metric_time__day + , subq_4.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -120,115 +142,137 @@ FROM ( subq_2.metric_time__day ) subq_3 ON - subq_4.metric_time__day = subq_3.metric_time__day - ) subq_6 + subq_6.metric_time__day = subq_3.metric_time__day + ) subq_7 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - subq_17.metric_time__day AS metric_time__day - , subq_16.buys AS buys + subq_20.metric_time__day AS metric_time__day + , subq_17.buys AS buys FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_18.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_18 - ) subq_17 + subq_19.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_18.ds__day AS metric_time__day + , subq_18.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + ) subq_19 + ) subq_20 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_15.metric_time__day - , SUM(subq_15.buys) AS buys + subq_16.metric_time__day + , SUM(subq_16.buys) AS buys FROM ( -- Pass Only Elements: ['buys', 'metric_time__day'] SELECT - subq_14.metric_time__day - , subq_14.buys + subq_15.metric_time__day + , subq_15.buys FROM ( -- Find conversions for user within the range of 7 day SELECT - subq_13.metric_time__day - , subq_13.user - , subq_13.buys - , subq_13.visits + subq_14.metric_time__day + , subq_14.user + , subq_14.buys + , subq_14.visits FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_9.visits) OVER ( + FIRST_VALUE(subq_10.visits) OVER ( PARTITION BY - subq_12.user - , subq_12.metric_time__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.metric_time__day DESC + subq_13.user + , subq_13.metric_time__day + , subq_13.mf_internal_uuid + ORDER BY subq_10.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_9.metric_time__day) OVER ( + , FIRST_VALUE(subq_10.metric_time__day) OVER ( PARTITION BY - subq_12.user - , subq_12.metric_time__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.metric_time__day DESC + subq_13.user + , subq_13.metric_time__day + , subq_13.mf_internal_uuid + ORDER BY subq_10.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day - , FIRST_VALUE(subq_9.user) OVER ( + , FIRST_VALUE(subq_10.user) OVER ( PARTITION BY - subq_12.user - , subq_12.metric_time__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.metric_time__day DESC + subq_13.user + , subq_13.metric_time__day + , subq_13.mf_internal_uuid + ORDER BY subq_10.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_12.mf_internal_uuid AS mf_internal_uuid - , subq_12.buys AS buys + , subq_13.mf_internal_uuid AS mf_internal_uuid + , subq_13.buys AS buys FROM ( -- Pass Only Elements: ['visits', 'metric_time__day', 'user'] SELECT - subq_8.metric_time__day - , subq_8.user - , subq_8.visits + subq_9.metric_time__day + , subq_9.user + , subq_9.visits FROM ( -- Metric Time Dimension 'ds' SELECT - subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.visit__ds__day - , subq_7.visit__ds__week - , subq_7.visit__ds__month - , subq_7.visit__ds__quarter - , subq_7.visit__ds__year - , subq_7.visit__ds__extract_year - , subq_7.visit__ds__extract_quarter - , subq_7.visit__ds__extract_month - , subq_7.visit__ds__extract_day - , subq_7.visit__ds__extract_dow - , subq_7.visit__ds__extract_doy - , subq_7.ds__day AS metric_time__day - , subq_7.ds__week AS metric_time__week - , subq_7.ds__month AS metric_time__month - , subq_7.ds__quarter AS metric_time__quarter - , subq_7.ds__year AS metric_time__year - , subq_7.ds__extract_year AS metric_time__extract_year - , subq_7.ds__extract_quarter AS metric_time__extract_quarter - , subq_7.ds__extract_month AS metric_time__extract_month - , subq_7.ds__extract_day AS metric_time__extract_day - , subq_7.ds__extract_dow AS metric_time__extract_dow - , subq_7.ds__extract_doy AS metric_time__extract_doy - , subq_7.user - , subq_7.session - , subq_7.visit__user - , subq_7.visit__session - , subq_7.referrer_id - , subq_7.visit__referrer_id - , subq_7.visits - , subq_7.visitors + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.visit__ds__day + , subq_8.visit__ds__week + , subq_8.visit__ds__month + , subq_8.visit__ds__quarter + , subq_8.visit__ds__year + , subq_8.visit__ds__extract_year + , subq_8.visit__ds__extract_quarter + , subq_8.visit__ds__extract_month + , subq_8.visit__ds__extract_day + , subq_8.visit__ds__extract_dow + , subq_8.visit__ds__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy + , subq_8.user + , subq_8.session + , subq_8.visit__user + , subq_8.visit__session + , subq_8.referrer_id + , subq_8.visit__referrer_id + , subq_8.visits + , subq_8.visitors FROM ( -- Read Elements From Semantic Model 'visits_source' SELECT @@ -263,118 +307,118 @@ FROM ( , visits_source_src_28000.user_id AS visit__user , visits_source_src_28000.session_id AS visit__session FROM ***************************.fct_visits visits_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 + ) subq_8 + ) subq_9 + ) subq_10 INNER JOIN ( -- Add column with generated UUID SELECT - subq_11.ds__day - , subq_11.ds__week - , subq_11.ds__month - , subq_11.ds__quarter - , subq_11.ds__year - , subq_11.ds__extract_year - , subq_11.ds__extract_quarter - , subq_11.ds__extract_month - , subq_11.ds__extract_day - , subq_11.ds__extract_dow - , subq_11.ds__extract_doy - , subq_11.ds_month__month - , subq_11.ds_month__quarter - , subq_11.ds_month__year - , subq_11.ds_month__extract_year - , subq_11.ds_month__extract_quarter - , subq_11.ds_month__extract_month - , subq_11.buy__ds__day - , subq_11.buy__ds__week - , subq_11.buy__ds__month - , subq_11.buy__ds__quarter - , subq_11.buy__ds__year - , subq_11.buy__ds__extract_year - , subq_11.buy__ds__extract_quarter - , subq_11.buy__ds__extract_month - , subq_11.buy__ds__extract_day - , subq_11.buy__ds__extract_dow - , subq_11.buy__ds__extract_doy - , subq_11.buy__ds_month__month - , subq_11.buy__ds_month__quarter - , subq_11.buy__ds_month__year - , subq_11.buy__ds_month__extract_year - , subq_11.buy__ds_month__extract_quarter - , subq_11.buy__ds_month__extract_month - , subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__month - , subq_11.metric_time__quarter - , subq_11.metric_time__year - , subq_11.metric_time__extract_year - , subq_11.metric_time__extract_quarter - , subq_11.metric_time__extract_month - , subq_11.metric_time__extract_day - , subq_11.metric_time__extract_dow - , subq_11.metric_time__extract_doy - , subq_11.user - , subq_11.session_id - , subq_11.buy__user - , subq_11.buy__session_id - , subq_11.buys - , subq_11.buyers + subq_12.ds__day + , subq_12.ds__week + , subq_12.ds__month + , subq_12.ds__quarter + , subq_12.ds__year + , subq_12.ds__extract_year + , subq_12.ds__extract_quarter + , subq_12.ds__extract_month + , subq_12.ds__extract_day + , subq_12.ds__extract_dow + , subq_12.ds__extract_doy + , subq_12.ds_month__month + , subq_12.ds_month__quarter + , subq_12.ds_month__year + , subq_12.ds_month__extract_year + , subq_12.ds_month__extract_quarter + , subq_12.ds_month__extract_month + , subq_12.buy__ds__day + , subq_12.buy__ds__week + , subq_12.buy__ds__month + , subq_12.buy__ds__quarter + , subq_12.buy__ds__year + , subq_12.buy__ds__extract_year + , subq_12.buy__ds__extract_quarter + , subq_12.buy__ds__extract_month + , subq_12.buy__ds__extract_day + , subq_12.buy__ds__extract_dow + , subq_12.buy__ds__extract_doy + , subq_12.buy__ds_month__month + , subq_12.buy__ds_month__quarter + , subq_12.buy__ds_month__year + , subq_12.buy__ds_month__extract_year + , subq_12.buy__ds_month__extract_quarter + , subq_12.buy__ds_month__extract_month + , subq_12.metric_time__day + , subq_12.metric_time__week + , subq_12.metric_time__month + , subq_12.metric_time__quarter + , subq_12.metric_time__year + , subq_12.metric_time__extract_year + , subq_12.metric_time__extract_quarter + , subq_12.metric_time__extract_month + , subq_12.metric_time__extract_day + , subq_12.metric_time__extract_dow + , subq_12.metric_time__extract_doy + , subq_12.user + , subq_12.session_id + , subq_12.buy__user + , subq_12.buy__session_id + , subq_12.buys + , subq_12.buyers , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( -- Metric Time Dimension 'ds' SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.ds_month__month - , subq_10.ds_month__quarter - , subq_10.ds_month__year - , subq_10.ds_month__extract_year - , subq_10.ds_month__extract_quarter - , subq_10.ds_month__extract_month - , subq_10.buy__ds__day - , subq_10.buy__ds__week - , subq_10.buy__ds__month - , subq_10.buy__ds__quarter - , subq_10.buy__ds__year - , subq_10.buy__ds__extract_year - , subq_10.buy__ds__extract_quarter - , subq_10.buy__ds__extract_month - , subq_10.buy__ds__extract_day - , subq_10.buy__ds__extract_dow - , subq_10.buy__ds__extract_doy - , subq_10.buy__ds_month__month - , subq_10.buy__ds_month__quarter - , subq_10.buy__ds_month__year - , subq_10.buy__ds_month__extract_year - , subq_10.buy__ds_month__extract_quarter - , subq_10.buy__ds_month__extract_month - , subq_10.ds__day AS metric_time__day - , subq_10.ds__week AS metric_time__week - , subq_10.ds__month AS metric_time__month - , subq_10.ds__quarter AS metric_time__quarter - , subq_10.ds__year AS metric_time__year - , subq_10.ds__extract_year AS metric_time__extract_year - , subq_10.ds__extract_quarter AS metric_time__extract_quarter - , subq_10.ds__extract_month AS metric_time__extract_month - , subq_10.ds__extract_day AS metric_time__extract_day - , subq_10.ds__extract_dow AS metric_time__extract_dow - , subq_10.ds__extract_doy AS metric_time__extract_doy - , subq_10.user - , subq_10.session_id - , subq_10.buy__user - , subq_10.buy__session_id - , subq_10.buys - , subq_10.buyers + subq_11.ds__day + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , subq_11.ds__year + , subq_11.ds__extract_year + , subq_11.ds__extract_quarter + , subq_11.ds__extract_month + , subq_11.ds__extract_day + , subq_11.ds__extract_dow + , subq_11.ds__extract_doy + , subq_11.ds_month__month + , subq_11.ds_month__quarter + , subq_11.ds_month__year + , subq_11.ds_month__extract_year + , subq_11.ds_month__extract_quarter + , subq_11.ds_month__extract_month + , subq_11.buy__ds__day + , subq_11.buy__ds__week + , subq_11.buy__ds__month + , subq_11.buy__ds__quarter + , subq_11.buy__ds__year + , subq_11.buy__ds__extract_year + , subq_11.buy__ds__extract_quarter + , subq_11.buy__ds__extract_month + , subq_11.buy__ds__extract_day + , subq_11.buy__ds__extract_dow + , subq_11.buy__ds__extract_doy + , subq_11.buy__ds_month__month + , subq_11.buy__ds_month__quarter + , subq_11.buy__ds_month__year + , subq_11.buy__ds_month__extract_year + , subq_11.buy__ds_month__extract_quarter + , subq_11.buy__ds_month__extract_month + , subq_11.ds__day AS metric_time__day + , subq_11.ds__week AS metric_time__week + , subq_11.ds__month AS metric_time__month + , subq_11.ds__quarter AS metric_time__quarter + , subq_11.ds__year AS metric_time__year + , subq_11.ds__extract_year AS metric_time__extract_year + , subq_11.ds__extract_quarter AS metric_time__extract_quarter + , subq_11.ds__extract_month AS metric_time__extract_month + , subq_11.ds__extract_day AS metric_time__extract_day + , subq_11.ds__extract_dow AS metric_time__extract_dow + , subq_11.ds__extract_doy AS metric_time__extract_doy + , subq_11.user + , subq_11.session_id + , subq_11.buy__user + , subq_11.buy__session_id + , subq_11.buys + , subq_11.buyers FROM ( -- Read Elements From Semantic Model 'buys_source' SELECT @@ -420,30 +464,30 @@ FROM ( , buys_source_src_28000.user_id AS buy__user , buys_source_src_28000.session_id AS buy__session_id FROM ***************************.fct_buys buys_source_src_28000 - ) subq_10 - ) subq_11 - ) subq_12 + ) subq_11 + ) subq_12 + ) subq_13 ON ( - subq_9.user = subq_12.user + subq_10.user = subq_13.user ) AND ( ( - subq_9.metric_time__day <= subq_12.metric_time__day + subq_10.metric_time__day <= subq_13.metric_time__day ) AND ( - subq_9.metric_time__day > subq_12.metric_time__day - INTERVAL 7 day + subq_10.metric_time__day > subq_13.metric_time__day - INTERVAL 7 day ) ) - ) subq_13 - ) subq_14 - ) subq_15 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY - subq_15.metric_time__day - ) subq_16 + subq_16.metric_time__day + ) subq_17 ON - subq_17.metric_time__day = subq_16.metric_time__day - ) subq_19 + subq_20.metric_time__day = subq_17.metric_time__day + ) subq_21 ON - subq_6.metric_time__day = subq_19.metric_time__day + subq_7.metric_time__day = subq_21.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_19.metric_time__day) -) subq_20 + COALESCE(subq_7.metric_time__day, subq_21.metric_time__day) +) subq_22 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index f93bee27a..1bab2d34d 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql @@ -21,15 +21,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_27.metric_time__day, subq_39.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_27.visits), 0) AS visits - , COALESCE(MAX(subq_39.buys), 0) AS buys + COALESCE(subq_30.metric_time__day, subq_43.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_30.visits), 0) AS visits + , COALESCE(MAX(subq_43.buys), 0) AS buys FROM ( -- Join to Time Spine Dataset SELECT - subq_26.ds AS metric_time__day - , subq_24.visits AS visits - FROM ***************************.mf_time_spine subq_26 + time_spine_src_28006.ds AS metric_time__day + , subq_26.visits AS visits + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28019 -- Pass Only Elements: ['visits', 'metric_time__day'] @@ -40,16 +40,16 @@ FROM ( FROM sma_28019_cte sma_28019_cte GROUP BY metric_time__day - ) subq_24 + ) subq_26 ON - subq_26.ds = subq_24.metric_time__day - ) subq_27 + time_spine_src_28006.ds = subq_26.metric_time__day + ) subq_30 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - subq_38.ds AS metric_time__day - , subq_36.buys AS buys - FROM ***************************.mf_time_spine subq_38 + time_spine_src_28006.ds AS metric_time__day + , subq_39.buys AS buys + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -62,30 +62,30 @@ FROM ( SELECT DISTINCT FIRST_VALUE(sma_28019_cte.visits) OVER ( PARTITION BY - subq_32.user - , subq_32.metric_time__day - , subq_32.mf_internal_uuid + subq_35.user + , subq_35.metric_time__day + , subq_35.mf_internal_uuid ORDER BY sma_28019_cte.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits , FIRST_VALUE(sma_28019_cte.metric_time__day) OVER ( PARTITION BY - subq_32.user - , subq_32.metric_time__day - , subq_32.mf_internal_uuid + subq_35.user + , subq_35.metric_time__day + , subq_35.mf_internal_uuid ORDER BY sma_28019_cte.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day , FIRST_VALUE(sma_28019_cte.user) OVER ( PARTITION BY - subq_32.user - , subq_32.metric_time__day - , subq_32.mf_internal_uuid + subq_35.user + , subq_35.metric_time__day + , subq_35.mf_internal_uuid ORDER BY sma_28019_cte.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_32.mf_internal_uuid AS mf_internal_uuid - , subq_32.buys AS buys + , subq_35.mf_internal_uuid AS mf_internal_uuid + , subq_35.buys AS buys FROM sma_28019_cte sma_28019_cte INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' @@ -97,26 +97,26 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_32 + ) subq_35 ON ( - sma_28019_cte.user = subq_32.user + sma_28019_cte.user = subq_35.user ) AND ( ( - sma_28019_cte.metric_time__day <= subq_32.metric_time__day + sma_28019_cte.metric_time__day <= subq_35.metric_time__day ) AND ( - sma_28019_cte.metric_time__day > subq_32.metric_time__day - INTERVAL 7 day + sma_28019_cte.metric_time__day > subq_35.metric_time__day - INTERVAL 7 day ) ) - ) subq_33 + ) subq_36 GROUP BY metric_time__day - ) subq_36 + ) subq_39 ON - subq_38.ds = subq_36.metric_time__day - ) subq_39 + time_spine_src_28006.ds = subq_39.metric_time__day + ) subq_43 ON - subq_27.metric_time__day = subq_39.metric_time__day + subq_30.metric_time__day = subq_43.metric_time__day GROUP BY - COALESCE(subq_27.metric_time__day, subq_39.metric_time__day) -) subq_40 + COALESCE(subq_30.metric_time__day, subq_43.metric_time__day) +) subq_44 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml index 352d701da..fa3418d78 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml @@ -6,19 +6,19 @@ docstring: - - + + - + - + @@ -34,11 +34,11 @@ docstring: - + - - + + @@ -51,11 +51,11 @@ docstring: - + - - - + + + @@ -66,21 +66,96 @@ docstring: - - + + - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -489,43 +564,118 @@ docstring: - + - - - + + + - - + + - - + + - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -533,50 +683,50 @@ docstring: - + - + - + - + - - + + - + - + - + - + - + - + - + @@ -594,19 +744,19 @@ docstring: - + - + - + - - + + @@ -614,239 +764,239 @@ docstring: - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1010,260 +1160,260 @@ docstring: - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1271,273 +1421,273 @@ docstring: - + - + - + - - - - - - - - - - - + - + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql index 8e1e4d0e9..8ee78b084 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: DuckDB --- -- Re-aggregate Metric via Group By SELECT - subq_11.booking__ds__month - , subq_11.metric_time__week - , subq_11.every_two_days_bookers_fill_nulls_with_0 + subq_12.booking__ds__month + , subq_12.metric_time__week + , subq_12.every_two_days_bookers_fill_nulls_with_0 FROM ( -- Window Function for Metric Re-aggregation SELECT - subq_10.booking__ds__month - , subq_10.metric_time__week - , FIRST_VALUE(subq_10.every_two_days_bookers_fill_nulls_with_0) OVER ( + subq_11.booking__ds__month + , subq_11.metric_time__week + , FIRST_VALUE(subq_11.every_two_days_bookers_fill_nulls_with_0) OVER ( PARTITION BY - subq_10.booking__ds__month - , subq_10.metric_time__week - ORDER BY subq_10.metric_time__day + subq_11.booking__ds__month + , subq_11.metric_time__week + ORDER BY subq_11.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS every_two_days_bookers_fill_nulls_with_0 FROM ( -- Compute Metrics via Expressions SELECT - subq_9.booking__ds__month - , subq_9.metric_time__day - , subq_9.metric_time__week - , COALESCE(subq_9.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 + subq_10.booking__ds__month + , subq_10.metric_time__week + , subq_10.metric_time__day + , COALESCE(subq_10.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_7.booking__ds__month AS booking__ds__month - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__week AS metric_time__week + subq_9.booking__ds__month AS booking__ds__month + , subq_9.metric_time__week AS metric_time__week + , subq_9.metric_time__day AS metric_time__day , subq_6.bookers AS bookers FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['booking__ds__month', 'metric_time__week', 'metric_time__day'] SELECT - DATE_TRUNC('month', subq_8.ds) AS booking__ds__month - , subq_8.ds AS metric_time__day - , DATE_TRUNC('week', subq_8.ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.booking__ds__month + , subq_8.metric_time__week + , subq_8.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__month AS booking__ds__month + , subq_7.ds__week AS metric_time__week + , subq_7.ds__day AS metric_time__day + , subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -377,11 +403,11 @@ FROM ( , subq_5.metric_time__week ) subq_6 ON - subq_7.metric_time__day = subq_6.metric_time__day - ) subq_9 - ) subq_10 -) subq_11 + subq_9.metric_time__day = subq_6.metric_time__day + ) subq_10 + ) subq_11 +) subq_12 GROUP BY - subq_11.booking__ds__month - , subq_11.metric_time__week - , subq_11.every_two_days_bookers_fill_nulls_with_0 + subq_12.booking__ds__month + , subq_12.metric_time__week + , subq_12.every_two_days_bookers_fill_nulls_with_0 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql index 3e431cfda..e22a6a683 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -27,38 +27,38 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('month', subq_20.ds) AS booking__ds__month - , subq_20.ds AS metric_time__day - , DATE_TRUNC('week', subq_20.ds) AS metric_time__week - , subq_18.bookers AS bookers - FROM ***************************.mf_time_spine subq_20 + DATE_TRUNC('month', time_spine_src_28006.ds) AS booking__ds__month + , DATE_TRUNC('week', time_spine_src_28006.ds) AS metric_time__week + , time_spine_src_28006.ds AS metric_time__day + , subq_19.bookers AS bookers + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] -- Aggregate Measures SELECT - DATE_TRUNC('month', subq_15.ds) AS booking__ds__month - , subq_15.ds AS metric_time__day - , DATE_TRUNC('week', subq_15.ds) AS metric_time__week + DATE_TRUNC('month', subq_16.ds) AS booking__ds__month + , subq_16.ds AS metric_time__day + , DATE_TRUNC('week', subq_16.ds) AS metric_time__week , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine subq_16 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_16.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_16.ds - INTERVAL 2 day ) GROUP BY - DATE_TRUNC('month', subq_15.ds) - , subq_15.ds - , DATE_TRUNC('week', subq_15.ds) - ) subq_18 + DATE_TRUNC('month', subq_16.ds) + , subq_16.ds + , DATE_TRUNC('week', subq_16.ds) + ) subq_19 ON - subq_20.ds = subq_18.metric_time__day - ) subq_21 -) subq_23 + time_spine_src_28006.ds = subq_19.metric_time__day + ) subq_23 +) subq_25 GROUP BY booking__ds__month , metric_time__week diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index 3b2fd2207..7d2f0270f 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__martian_day - , subq_7.bookings AS bookings_join_to_time_spine + subq_8.metric_time__martian_day + , subq_8.bookings AS bookings_join_to_time_spine FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__martian_day AS metric_time__martian_day + subq_7.metric_time__martian_day AS metric_time__martian_day , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__martian_day',] SELECT - subq_6.martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_6 + subq_6.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__day + , subq_5.ds__day + , subq_5.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 GROUP BY - subq_6.martian_day - ) subq_5 + subq_6.metric_time__martian_day + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -235,5 +259,5 @@ FROM ( subq_3.metric_time__martian_day ) subq_4 ON - subq_5.metric_time__martian_day = subq_4.metric_time__martian_day -) subq_7 + subq_7.metric_time__martian_day = subq_4.metric_time__martian_day +) subq_8 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index 2b21a9d62..efe04ccdc 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_13.metric_time__martian_day AS metric_time__martian_day - , subq_12.bookings AS bookings_join_to_time_spine + subq_16.metric_time__martian_day AS metric_time__martian_day + , subq_13.bookings AS bookings_join_to_time_spine FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__martian_day',] SELECT martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY martian_day -) subq_13 +) subq_16 LEFT OUTER JOIN ( -- Metric Time Dimension 'ds' -- Join to Custom Granularity Dataset -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] -- Aggregate Measures SELECT - subq_9.martian_day AS metric_time__martian_day - , SUM(subq_8.bookings) AS bookings + subq_10.martian_day AS metric_time__martian_day + , SUM(subq_9.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT 1 AS bookings , DATE_TRUNC('day', ds) AS ds__day FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 + ) subq_9 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_10 ON - subq_8.ds__day = subq_9.ds + subq_9.ds__day = subq_10.ds GROUP BY - subq_9.martian_day -) subq_12 + subq_10.martian_day +) subq_13 ON - subq_13.metric_time__martian_day = subq_12.metric_time__martian_day + subq_16.metric_time__martian_day = subq_13.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql index 7d92f42a8..3f621b90e 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.booking__ds__martian_day + subq_9.booking__ds__martian_day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_7.booking__ds__martian_day - , subq_7.bookings AS bookings_5_days_ago + subq_8.booking__ds__martian_day + , subq_8.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_6.booking__ds__martian_day - , SUM(subq_6.bookings) AS bookings + subq_7.booking__ds__martian_day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__ds__martian_day'] SELECT - subq_5.booking__ds__martian_day - , subq_5.bookings + subq_6.booking__ds__martian_day + , subq_6.bookings FROM ( -- Join to Time Spine Dataset -- Join to Custom Granularity Dataset @@ -101,7 +101,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.booking__ds__day AS booking__ds__day + , subq_4.booking__ds__day AS booking__ds__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -123,13 +123,35 @@ FROM ( , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99 , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 - , subq_4.martian_day AS booking__ds__martian_day + , subq_5.martian_day AS booking__ds__martian_day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['booking__ds__day', 'booking__ds__day'] SELECT - subq_3.ds AS booking__ds__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.booking__ds__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS booking__ds__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -326,14 +348,14 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.booking__ds__day - INTERVAL 5 day = subq_1.booking__ds__day + subq_4.booking__ds__day - INTERVAL 5 day = subq_1.booking__ds__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_4 + ***************************.mf_time_spine subq_5 ON - subq_2.booking__ds__day = subq_4.ds - ) subq_5 - ) subq_6 + subq_4.booking__ds__day = subq_5.ds + ) subq_6 + ) subq_7 GROUP BY - subq_6.booking__ds__martian_day - ) subq_7 -) subq_8 + subq_7.booking__ds__martian_day + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql index 9b358e093..7de34b0ee 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql @@ -13,9 +13,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_13.martian_day AS booking__ds__martian_day - , SUM(subq_10.bookings) AS bookings_5_days_ago - FROM ***************************.mf_time_spine subq_12 + subq_15.martian_day AS booking__ds__martian_day + , SUM(subq_11.bookings) AS bookings_5_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -23,13 +23,13 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - subq_12.ds - INTERVAL 5 day = subq_10.booking__ds__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_11.booking__ds__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_13 + ***************************.mf_time_spine subq_15 ON - subq_12.ds = subq_13.ds + time_spine_src_28006.ds = subq_15.ds GROUP BY - subq_13.martian_day -) subq_17 + subq_15.martian_day +) subq_19 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index 1a5b63411..0868ab652 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day + subq_10.metric_time__day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.bookings AS bookings_5_days_ago + subq_9.metric_time__day + , subq_9.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__day - , SUM(subq_7.bookings) AS bookings + subq_8.metric_time__day + , SUM(subq_8.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_7.metric_time__day + , subq_7.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_5.metric_time__martian_day - , subq_5.metric_time__day - , subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.ds_partitioned__day - , subq_5.ds_partitioned__week - , subq_5.ds_partitioned__month - , subq_5.ds_partitioned__quarter - , subq_5.ds_partitioned__year - , subq_5.ds_partitioned__extract_year - , subq_5.ds_partitioned__extract_quarter - , subq_5.ds_partitioned__extract_month - , subq_5.ds_partitioned__extract_day - , subq_5.ds_partitioned__extract_dow - , subq_5.ds_partitioned__extract_doy - , subq_5.paid_at__day - , subq_5.paid_at__week - , subq_5.paid_at__month - , subq_5.paid_at__quarter - , subq_5.paid_at__year - , subq_5.paid_at__extract_year - , subq_5.paid_at__extract_quarter - , subq_5.paid_at__extract_month - , subq_5.paid_at__extract_day - , subq_5.paid_at__extract_dow - , subq_5.paid_at__extract_doy - , subq_5.booking__ds__day - , subq_5.booking__ds__week - , subq_5.booking__ds__month - , subq_5.booking__ds__quarter - , subq_5.booking__ds__year - , subq_5.booking__ds__extract_year - , subq_5.booking__ds__extract_quarter - , subq_5.booking__ds__extract_month - , subq_5.booking__ds__extract_day - , subq_5.booking__ds__extract_dow - , subq_5.booking__ds__extract_doy - , subq_5.booking__ds_partitioned__day - , subq_5.booking__ds_partitioned__week - , subq_5.booking__ds_partitioned__month - , subq_5.booking__ds_partitioned__quarter - , subq_5.booking__ds_partitioned__year - , subq_5.booking__ds_partitioned__extract_year - , subq_5.booking__ds_partitioned__extract_quarter - , subq_5.booking__ds_partitioned__extract_month - , subq_5.booking__ds_partitioned__extract_day - , subq_5.booking__ds_partitioned__extract_dow - , subq_5.booking__ds_partitioned__extract_doy - , subq_5.booking__paid_at__day - , subq_5.booking__paid_at__week - , subq_5.booking__paid_at__month - , subq_5.booking__paid_at__quarter - , subq_5.booking__paid_at__year - , subq_5.booking__paid_at__extract_year - , subq_5.booking__paid_at__extract_quarter - , subq_5.booking__paid_at__extract_month - , subq_5.booking__paid_at__extract_day - , subq_5.booking__paid_at__extract_dow - , subq_5.booking__paid_at__extract_doy - , subq_5.metric_time__week - , subq_5.metric_time__month - , subq_5.metric_time__quarter - , subq_5.metric_time__year - , subq_5.metric_time__extract_year - , subq_5.metric_time__extract_quarter - , subq_5.metric_time__extract_month - , subq_5.metric_time__extract_day - , subq_5.metric_time__extract_dow - , subq_5.metric_time__extract_doy - , subq_5.listing - , subq_5.guest - , subq_5.host - , subq_5.booking__listing - , subq_5.booking__guest - , subq_5.booking__host - , subq_5.is_instant - , subq_5.booking__is_instant - , subq_5.bookings - , subq_5.instant_bookings - , subq_5.booking_value - , subq_5.max_booking_value - , subq_5.min_booking_value - , subq_5.bookers - , subq_5.average_booking_value - , subq_5.referred_bookings - , subq_5.median_booking_value - , subq_5.booking_value_p99 - , subq_5.discrete_booking_value_p99 - , subq_5.approximate_continuous_booking_value_p99 - , subq_5.approximate_discrete_booking_value_p99 + subq_6.metric_time__martian_day + , subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__extract_doy + , subq_6.metric_time__week + , subq_6.metric_time__month + , subq_6.metric_time__quarter + , subq_6.metric_time__year + , subq_6.metric_time__extract_year + , subq_6.metric_time__extract_quarter + , subq_6.metric_time__extract_month + , subq_6.metric_time__extract_day + , subq_6.metric_time__extract_dow + , subq_6.metric_time__extract_doy + , subq_6.metric_time__day + , subq_6.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset -- Join to Custom Granularity Dataset @@ -203,7 +203,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -225,13 +225,35 @@ FROM ( , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99 , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 - , subq_4.martian_day AS metric_time__martian_day + , subq_5.martian_day AS metric_time__martian_day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,16 +450,16 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_4 + ***************************.mf_time_spine subq_5 ON - subq_2.metric_time__day = subq_4.ds - ) subq_5 + subq_4.metric_time__day = subq_5.ds + ) subq_6 WHERE metric_time__martian_day = '2020-01-01' - ) subq_6 - ) subq_7 + ) subq_7 + ) subq_8 GROUP BY - subq_7.metric_time__day - ) subq_8 -) subq_9 + subq_8.metric_time__day + ) subq_9 +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index a74e4042e..139cbfa16 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -18,10 +18,10 @@ FROM ( -- Join to Time Spine Dataset -- Join to Custom Granularity Dataset SELECT - subq_13.ds AS metric_time__day - , subq_11.bookings AS bookings - , subq_14.martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_13 + time_spine_src_28006.ds AS metric_time__day + , subq_12.bookings AS bookings + , subq_16.martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -29,15 +29,15 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + ) subq_12 ON - subq_13.ds - INTERVAL 5 day = subq_11.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_12.metric_time__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_14 + ***************************.mf_time_spine subq_16 ON - subq_13.ds = subq_14.ds - ) subq_15 + time_spine_src_28006.ds = subq_16.ds + ) subq_17 WHERE metric_time__martian_day = '2020-01-01' GROUP BY metric_time__day -) subq_19 +) subq_21 diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml index f8197f144..895447530 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml @@ -60,7 +60,7 @@ docstring: - + @@ -78,6 +78,11 @@ docstring: + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml index dbe84cd5d..7b83fc672 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml @@ -26,7 +26,7 @@ docstring: - + @@ -44,6 +44,11 @@ docstring: + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml index 88e7bab66..761d9b1cf 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml @@ -24,7 +24,7 @@ test_filename: test_dataflow_plan_builder.py - + @@ -42,6 +42,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml index 55d4a1678..50fb6005a 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml @@ -25,7 +25,7 @@ test_filename: test_dataflow_plan_builder.py - + @@ -43,6 +43,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml index ab0c43a9d..9832566a7 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml @@ -31,6 +31,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + @@ -79,13 +84,18 @@ test_filename: test_dataflow_plan_builder.py + + + + + - + @@ -103,6 +113,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml index 29dcfc8ad..eafb91229 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml @@ -58,7 +58,7 @@ docstring: - + @@ -71,13 +71,12 @@ docstring: + + + + + - - - - - - diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml index 474bca4b1..c4855938b 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml @@ -20,6 +20,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml index c4c72c23e..8934a0311 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml @@ -19,6 +19,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + @@ -44,7 +49,7 @@ test_filename: test_dataflow_plan_builder.py - + @@ -62,6 +67,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml index 85ac6913d..24643e555 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml @@ -112,7 +112,7 @@ docstring: - + @@ -170,6 +170,11 @@ docstring: + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml index 5734f04cd..1879434f9 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml @@ -114,7 +114,7 @@ docstring: - + @@ -175,6 +175,11 @@ docstring: + + + + + @@ -246,7 +251,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index c7ebdd463..b1a5dc422 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day + subq_12.metric_time__day , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.bookers AS every_2_days_bookers_2_days_ago + subq_11.metric_time__day + , subq_11.bookers AS every_2_days_bookers_2_days_ago FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , COUNT(DISTINCT subq_9.bookers) AS bookers + subq_10.metric_time__day + , COUNT(DISTINCT subq_10.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.bookers + subq_9.metric_time__day + , subq_9.bookers FROM ( -- Constrain Time Range to [2019-12-19T00:00:00, 2020-01-02T00:00:00] SELECT - subq_7.metric_time__day - , subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.ds_partitioned__day - , subq_7.ds_partitioned__week - , subq_7.ds_partitioned__month - , subq_7.ds_partitioned__quarter - , subq_7.ds_partitioned__year - , subq_7.ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy - , subq_7.paid_at__day - , subq_7.paid_at__week - , subq_7.paid_at__month - , subq_7.paid_at__quarter - , subq_7.paid_at__year - , subq_7.paid_at__extract_year - , subq_7.paid_at__extract_quarter - , subq_7.paid_at__extract_month - , subq_7.paid_at__extract_day - , subq_7.paid_at__extract_dow - , subq_7.paid_at__extract_doy - , subq_7.booking__ds__day - , subq_7.booking__ds__week - , subq_7.booking__ds__month - , subq_7.booking__ds__quarter - , subq_7.booking__ds__year - , subq_7.booking__ds__extract_year - , subq_7.booking__ds__extract_quarter - , subq_7.booking__ds__extract_month - , subq_7.booking__ds__extract_day - , subq_7.booking__ds__extract_dow - , subq_7.booking__ds__extract_doy - , subq_7.booking__ds_partitioned__day - , subq_7.booking__ds_partitioned__week - , subq_7.booking__ds_partitioned__month - , subq_7.booking__ds_partitioned__quarter - , subq_7.booking__ds_partitioned__year - , subq_7.booking__ds_partitioned__extract_year - , subq_7.booking__ds_partitioned__extract_quarter - , subq_7.booking__ds_partitioned__extract_month - , subq_7.booking__ds_partitioned__extract_day - , subq_7.booking__ds_partitioned__extract_dow - , subq_7.booking__ds_partitioned__extract_doy - , subq_7.booking__paid_at__day - , subq_7.booking__paid_at__week - , subq_7.booking__paid_at__month - , subq_7.booking__paid_at__quarter - , subq_7.booking__paid_at__year - , subq_7.booking__paid_at__extract_year - , subq_7.booking__paid_at__extract_quarter - , subq_7.booking__paid_at__extract_month - , subq_7.booking__paid_at__extract_day - , subq_7.booking__paid_at__extract_dow - , subq_7.booking__paid_at__extract_doy - , subq_7.metric_time__week - , subq_7.metric_time__month - , subq_7.metric_time__quarter - , subq_7.metric_time__year - , subq_7.metric_time__extract_year - , subq_7.metric_time__extract_quarter - , subq_7.metric_time__extract_month - , subq_7.metric_time__extract_day - , subq_7.metric_time__extract_dow - , subq_7.metric_time__extract_doy - , subq_7.listing - , subq_7.guest - , subq_7.host - , subq_7.booking__listing - , subq_7.booking__guest - , subq_7.booking__host - , subq_7.is_instant - , subq_7.booking__is_instant - , subq_7.bookings - , subq_7.instant_bookings - , subq_7.booking_value - , subq_7.max_booking_value - , subq_7.min_booking_value - , subq_7.bookers - , subq_7.average_booking_value - , subq_7.referred_bookings - , subq_7.median_booking_value - , subq_7.booking_value_p99 - , subq_7.discrete_booking_value_p99 - , subq_7.approximate_continuous_booking_value_p99 - , subq_7.approximate_discrete_booking_value_p99 + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.ds_partitioned__day + , subq_8.ds_partitioned__week + , subq_8.ds_partitioned__month + , subq_8.ds_partitioned__quarter + , subq_8.ds_partitioned__year + , subq_8.ds_partitioned__extract_year + , subq_8.ds_partitioned__extract_quarter + , subq_8.ds_partitioned__extract_month + , subq_8.ds_partitioned__extract_day + , subq_8.ds_partitioned__extract_dow + , subq_8.ds_partitioned__extract_doy + , subq_8.paid_at__day + , subq_8.paid_at__week + , subq_8.paid_at__month + , subq_8.paid_at__quarter + , subq_8.paid_at__year + , subq_8.paid_at__extract_year + , subq_8.paid_at__extract_quarter + , subq_8.paid_at__extract_month + , subq_8.paid_at__extract_day + , subq_8.paid_at__extract_dow + , subq_8.paid_at__extract_doy + , subq_8.booking__ds__day + , subq_8.booking__ds__week + , subq_8.booking__ds__month + , subq_8.booking__ds__quarter + , subq_8.booking__ds__year + , subq_8.booking__ds__extract_year + , subq_8.booking__ds__extract_quarter + , subq_8.booking__ds__extract_month + , subq_8.booking__ds__extract_day + , subq_8.booking__ds__extract_dow + , subq_8.booking__ds__extract_doy + , subq_8.booking__ds_partitioned__day + , subq_8.booking__ds_partitioned__week + , subq_8.booking__ds_partitioned__month + , subq_8.booking__ds_partitioned__quarter + , subq_8.booking__ds_partitioned__year + , subq_8.booking__ds_partitioned__extract_year + , subq_8.booking__ds_partitioned__extract_quarter + , subq_8.booking__ds_partitioned__extract_month + , subq_8.booking__ds_partitioned__extract_day + , subq_8.booking__ds_partitioned__extract_dow + , subq_8.booking__ds_partitioned__extract_doy + , subq_8.booking__paid_at__day + , subq_8.booking__paid_at__week + , subq_8.booking__paid_at__month + , subq_8.booking__paid_at__quarter + , subq_8.booking__paid_at__year + , subq_8.booking__paid_at__extract_year + , subq_8.booking__paid_at__extract_quarter + , subq_8.booking__paid_at__extract_month + , subq_8.booking__paid_at__extract_day + , subq_8.booking__paid_at__extract_dow + , subq_8.booking__paid_at__extract_doy + , subq_8.metric_time__week + , subq_8.metric_time__month + , subq_8.metric_time__quarter + , subq_8.metric_time__year + , subq_8.metric_time__extract_year + , subq_8.metric_time__extract_quarter + , subq_8.metric_time__extract_month + , subq_8.metric_time__extract_day + , subq_8.metric_time__extract_dow + , subq_8.metric_time__extract_doy + , subq_8.metric_time__day + , subq_8.listing + , subq_8.guest + , subq_8.host + , subq_8.booking__listing + , subq_8.booking__guest + , subq_8.booking__host + , subq_8.is_instant + , subq_8.booking__is_instant + , subq_8.bookings + , subq_8.instant_bookings + , subq_8.booking_value + , subq_8.max_booking_value + , subq_8.min_booking_value + , subq_8.bookers + , subq_8.average_booking_value + , subq_8.referred_bookings + , subq_8.median_booking_value + , subq_8.booking_value_p99 + , subq_8.discrete_booking_value_p99 + , subq_8.approximate_continuous_booking_value_p99 + , subq_8.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -201,7 +201,7 @@ FROM ( , subq_4.metric_time__extract_day AS metric_time__extract_day , subq_4.metric_time__extract_dow AS metric_time__extract_dow , subq_4.metric_time__extract_doy AS metric_time__extract_doy - , subq_5.metric_time__day AS metric_time__day + , subq_7.metric_time__day AS metric_time__day , subq_4.listing AS listing , subq_4.guest AS guest , subq_4.host AS host @@ -224,11 +224,33 @@ FROM ( , subq_4.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_4.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -539,12 +561,12 @@ FROM ( ) ) subq_4 ON - subq_5.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day - ) subq_7 - WHERE subq_7.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' - ) subq_8 - ) subq_9 + subq_7.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day + ) subq_8 + WHERE subq_8.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' + ) subq_9 + ) subq_10 GROUP BY - subq_9.metric_time__day - ) subq_10 -) subq_11 + subq_10.metric_time__day + ) subq_11 +) subq_12 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index c9708287a..90bd2622f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql @@ -13,27 +13,27 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_18.ds AS metric_time__day - , COUNT(DISTINCT subq_16.bookers) AS every_2_days_bookers_2_days_ago - FROM ***************************.mf_time_spine subq_18 + time_spine_src_28006.ds AS metric_time__day + , COUNT(DISTINCT subq_17.bookers) AS every_2_days_bookers_2_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Join Self Over Time Range SELECT - subq_15.ds AS metric_time__day + subq_16.ds AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine subq_16 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_16.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_16.ds - INTERVAL 2 day ) - ) subq_16 + ) subq_17 ON - subq_18.ds - INTERVAL 2 day = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + time_spine_src_28006.ds - INTERVAL 2 day = subq_17.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_18.ds -) subq_23 + time_spine_src_28006.ds +) subq_25 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index fda110dcf..ba396053f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__month + subq_8.metric_time__month , bookings_last_month AS bookings_last_month FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__month - , subq_6.bookings_monthly AS bookings_last_month + subq_7.metric_time__month + , subq_7.bookings_monthly AS bookings_last_month FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__month - , SUM(subq_5.bookings_monthly) AS bookings_monthly + subq_6.metric_time__month + , SUM(subq_6.bookings_monthly) AS bookings_monthly FROM ( -- Pass Only Elements: ['bookings_monthly', 'metric_time__month'] SELECT - subq_4.metric_time__month - , subq_4.bookings_monthly + subq_5.metric_time__month + , subq_5.bookings_monthly FROM ( -- Join to Time Spine Dataset SELECT @@ -41,18 +41,40 @@ FROM ( , subq_1.metric_time__extract_year AS metric_time__extract_year , subq_1.metric_time__extract_quarter AS metric_time__extract_quarter , subq_1.metric_time__extract_month AS metric_time__extract_month - , subq_2.metric_time__month AS metric_time__month + , subq_4.metric_time__month AS metric_time__month , subq_1.listing AS listing , subq_1.booking_monthly__listing AS booking_monthly__listing , subq_1.bookings_monthly AS bookings_monthly FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__month', 'metric_time__month'] SELECT - DATE_TRUNC('month', subq_3.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_3 + subq_3.metric_time__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__month AS metric_time__month + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_16006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_16006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_16006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_16006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_16006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_16006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_16006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_16006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_16006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_16006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_16006.ds) AS ds__extract_doy + , time_spine_src_16006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_16006 + ) subq_2 + ) subq_3 GROUP BY - DATE_TRUNC('month', subq_3.ds) - ) subq_2 + subq_3.metric_time__month + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -99,10 +121,10 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__month - INTERVAL 1 month = subq_1.metric_time__month - ) subq_4 - ) subq_5 + subq_4.metric_time__month - INTERVAL 1 month = subq_1.metric_time__month + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__month - ) subq_6 -) subq_7 + subq_6.metric_time__month + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 4c78ac742..d7a896562 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql @@ -12,20 +12,22 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_10.metric_time__month AS metric_time__month + subq_13.metric_time__month AS metric_time__month , SUM(monthly_bookings_source_src_16000.bookings_monthly) AS bookings_last_month FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__month', 'metric_time__month'] SELECT DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_11 + FROM ***************************.mf_time_spine time_spine_src_16006 GROUP BY DATE_TRUNC('month', ds) - ) subq_10 + ) subq_13 INNER JOIN ***************************.fct_bookings_extended_monthly monthly_bookings_source_src_16000 ON - subq_10.metric_time__month - INTERVAL 1 month = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + subq_13.metric_time__month - INTERVAL 1 month = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) GROUP BY - subq_10.metric_time__month -) subq_15 + subq_13.metric_time__month +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql index 245d56f88..6c821139f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_14.metric_time__day , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) AS metric_time__day + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) AS metric_time__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + , MAX(subq_13.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.bookings AS bookings_at_start_of_month + subq_12.metric_time__day + , subq_12.bookings AS bookings_at_start_of_month FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__day - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day + , subq_9.metric_time__day AS metric_time__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,33 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +567,15 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_TRUNC('month', subq_9.metric_time__day) = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__day - ) subq_11 - ) subq_12 + subq_11.metric_time__day + ) subq_12 + ) subq_13 ON - subq_4.metric_time__day = subq_12.metric_time__day + subq_4.metric_time__day = subq_13.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) -) subq_13 + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index d7456bd9d..e72d76df2 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY metric_time__day - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS metric_time__day - , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_21.bookings) AS bookings_at_start_of_month + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + time_spine_src_28006.ds + ) subq_28 ON - subq_18.metric_time__day = subq_26.metric_time__day + subq_19.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) -) subq_27 + COALESCE(subq_19.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index bf9ad8dd4..6ed57c892 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__week + subq_14.metric_time__week , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__week, subq_12.metric_time__week) AS metric_time__week + COALESCE(subq_4.metric_time__week, subq_13.metric_time__week) AS metric_time__week , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + , MAX(subq_13.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__week - , subq_11.bookings AS bookings_at_start_of_month + subq_12.metric_time__week + , subq_12.bookings AS bookings_at_start_of_month FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__week - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__week + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__week'] SELECT - subq_9.metric_time__week - , subq_9.bookings + subq_10.metric_time__week + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -320,8 +320,8 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__week AS metric_time__week + , subq_9.metric_time__day AS metric_time__day + , subq_9.metric_time__week AS metric_time__week , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,12 +344,36 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__week'] SELECT - subq_8.ds AS metric_time__day - , DATE_TRUNC('week', subq_8.ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + , subq_8.metric_time__week + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__week + , subq_7.ds__day + , subq_7.ds__week + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,16 +570,16 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day - WHERE subq_7.metric_time__week = subq_7.metric_time__day - ) subq_9 - ) subq_10 + DATE_TRUNC('month', subq_9.metric_time__day) = subq_6.metric_time__day + WHERE subq_9.metric_time__week = subq_9.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__week - ) subq_11 - ) subq_12 + subq_11.metric_time__week + ) subq_12 + ) subq_13 ON - subq_4.metric_time__week = subq_12.metric_time__week + subq_4.metric_time__week = subq_13.metric_time__week GROUP BY - COALESCE(subq_4.metric_time__week, subq_12.metric_time__week) -) subq_13 + COALESCE(subq_4.metric_time__week, subq_13.metric_time__week) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index cfa6d1f5e..d26cf723d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__week, subq_26.metric_time__week) AS metric_time__week - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__week, subq_28.metric_time__week) AS metric_time__week + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('week', ds) AS metric_time__week , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY metric_time__week - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__week'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('week', subq_22.ds) AS metric_time__week - , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('week', time_spine_src_28006.ds) AS metric_time__week + , SUM(subq_21.bookings) AS bookings_at_start_of_month + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,15 +46,15 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day - WHERE DATE_TRUNC('week', subq_22.ds) = subq_22.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = subq_21.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = time_spine_src_28006.ds GROUP BY - DATE_TRUNC('week', subq_22.ds) - ) subq_26 + DATE_TRUNC('week', time_spine_src_28006.ds) + ) subq_28 ON - subq_18.metric_time__week = subq_26.metric_time__week + subq_19.metric_time__week = subq_28.metric_time__week GROUP BY - COALESCE(subq_18.metric_time__week, subq_26.metric_time__week) -) subq_27 + COALESCE(subq_19.metric_time__week, subq_28.metric_time__week) +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql index 3ec3c55d3..6845f9bc0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_14.metric_time__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) AS metric_time__day + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) AS metric_time__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.metric_time__day + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__day - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day + , subq_9.metric_time__day AS metric_time__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,33 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +567,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__day - ) subq_11 - ) subq_12 + subq_11.metric_time__day + ) subq_12 + ) subq_13 ON - subq_4.metric_time__day = subq_12.metric_time__day + subq_4.metric_time__day = subq_13.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) -) subq_13 + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql index 18cde7417..705f82e6b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY metric_time__day - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS metric_time__day - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_21.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + time_spine_src_28006.ds - INTERVAL 14 day = subq_21.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + time_spine_src_28006.ds + ) subq_28 ON - subq_18.metric_time__day = subq_26.metric_time__day + subq_19.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) -) subq_27 + COALESCE(subq_19.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 792cbdb25..d249202bf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__quarter + subq_14.metric_time__quarter , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__quarter, subq_12.metric_time__quarter) AS metric_time__quarter + COALESCE(subq_4.metric_time__quarter, subq_13.metric_time__quarter) AS metric_time__quarter , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__quarter - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.metric_time__quarter + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__quarter - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__quarter + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__quarter'] SELECT - subq_9.metric_time__quarter - , subq_9.bookings + subq_10.metric_time__quarter + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -320,8 +320,8 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__quarter AS metric_time__quarter + , subq_9.metric_time__day AS metric_time__day + , subq_9.metric_time__quarter AS metric_time__quarter , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,12 +344,36 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__quarter'] SELECT - subq_8.ds AS metric_time__day - , DATE_TRUNC('quarter', subq_8.ds) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + , subq_8.metric_time__quarter + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__day + , subq_7.ds__quarter + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +570,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__quarter - ) subq_11 - ) subq_12 + subq_11.metric_time__quarter + ) subq_12 + ) subq_13 ON - subq_4.metric_time__quarter = subq_12.metric_time__quarter + subq_4.metric_time__quarter = subq_13.metric_time__quarter GROUP BY - COALESCE(subq_4.metric_time__quarter, subq_12.metric_time__quarter) -) subq_13 + COALESCE(subq_4.metric_time__quarter, subq_13.metric_time__quarter) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index 42b79f2c6..29d1a6106 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__quarter, subq_26.metric_time__quarter) AS metric_time__quarter - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__quarter, subq_28.metric_time__quarter) AS metric_time__quarter + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('quarter', ds) AS metric_time__quarter , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY metric_time__quarter - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__quarter'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('quarter', subq_22.ds) AS metric_time__quarter - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('quarter', time_spine_src_28006.ds) AS metric_time__quarter + , SUM(subq_21.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + time_spine_src_28006.ds - INTERVAL 14 day = subq_21.metric_time__day GROUP BY - DATE_TRUNC('quarter', subq_22.ds) - ) subq_26 + DATE_TRUNC('quarter', time_spine_src_28006.ds) + ) subq_28 ON - subq_18.metric_time__quarter = subq_26.metric_time__quarter + subq_19.metric_time__quarter = subq_28.metric_time__quarter GROUP BY - COALESCE(subq_18.metric_time__quarter, subq_26.metric_time__quarter) -) subq_27 + COALESCE(subq_19.metric_time__quarter, subq_28.metric_time__quarter) +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 50ff9446a..04acc1d8f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_16.metric_time__day + subq_18.metric_time__day , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) AS metric_time__day - , MAX(subq_7.month_start_bookings) AS month_start_bookings - , MAX(subq_15.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) AS metric_time__day + , MAX(subq_8.month_start_bookings) AS month_start_bookings + , MAX(subq_17.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings AS month_start_bookings + subq_7.metric_time__day + , subq_7.bookings AS month_start_bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -106,7 +106,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -129,11 +129,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,236 +352,258 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_TRUNC('month', subq_4.metric_time__day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 + subq_6.metric_time__day + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day - , subq_14.bookings AS bookings_1_month_ago + subq_16.metric_time__day + , subq_16.bookings AS bookings_1_month_ago FROM ( -- Aggregate Measures SELECT - subq_13.metric_time__day - , SUM(subq_13.bookings) AS bookings + subq_15.metric_time__day + , SUM(subq_15.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_12.metric_time__day - , subq_12.bookings + subq_14.metric_time__day + , subq_14.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_9.ds__day AS ds__day - , subq_9.ds__week AS ds__week - , subq_9.ds__month AS ds__month - , subq_9.ds__quarter AS ds__quarter - , subq_9.ds__year AS ds__year - , subq_9.ds__extract_year AS ds__extract_year - , subq_9.ds__extract_quarter AS ds__extract_quarter - , subq_9.ds__extract_month AS ds__extract_month - , subq_9.ds__extract_day AS ds__extract_day - , subq_9.ds__extract_dow AS ds__extract_dow - , subq_9.ds__extract_doy AS ds__extract_doy - , subq_9.ds_partitioned__day AS ds_partitioned__day - , subq_9.ds_partitioned__week AS ds_partitioned__week - , subq_9.ds_partitioned__month AS ds_partitioned__month - , subq_9.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_9.ds_partitioned__year AS ds_partitioned__year - , subq_9.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_9.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_9.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_9.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_9.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_9.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_9.paid_at__day AS paid_at__day - , subq_9.paid_at__week AS paid_at__week - , subq_9.paid_at__month AS paid_at__month - , subq_9.paid_at__quarter AS paid_at__quarter - , subq_9.paid_at__year AS paid_at__year - , subq_9.paid_at__extract_year AS paid_at__extract_year - , subq_9.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_9.paid_at__extract_month AS paid_at__extract_month - , subq_9.paid_at__extract_day AS paid_at__extract_day - , subq_9.paid_at__extract_dow AS paid_at__extract_dow - , subq_9.paid_at__extract_doy AS paid_at__extract_doy - , subq_9.booking__ds__day AS booking__ds__day - , subq_9.booking__ds__week AS booking__ds__week - , subq_9.booking__ds__month AS booking__ds__month - , subq_9.booking__ds__quarter AS booking__ds__quarter - , subq_9.booking__ds__year AS booking__ds__year - , subq_9.booking__ds__extract_year AS booking__ds__extract_year - , subq_9.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_9.booking__ds__extract_month AS booking__ds__extract_month - , subq_9.booking__ds__extract_day AS booking__ds__extract_day - , subq_9.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_9.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_9.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_9.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_9.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_9.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_9.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_9.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_9.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_9.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_9.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_9.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_9.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_9.booking__paid_at__day AS booking__paid_at__day - , subq_9.booking__paid_at__week AS booking__paid_at__week - , subq_9.booking__paid_at__month AS booking__paid_at__month - , subq_9.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_9.booking__paid_at__year AS booking__paid_at__year - , subq_9.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_9.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_9.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_9.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_9.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_9.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_9.metric_time__week AS metric_time__week - , subq_9.metric_time__month AS metric_time__month - , subq_9.metric_time__quarter AS metric_time__quarter - , subq_9.metric_time__year AS metric_time__year - , subq_9.metric_time__extract_year AS metric_time__extract_year - , subq_9.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_9.metric_time__extract_month AS metric_time__extract_month - , subq_9.metric_time__extract_day AS metric_time__extract_day - , subq_9.metric_time__extract_dow AS metric_time__extract_dow - , subq_9.metric_time__extract_doy AS metric_time__extract_doy - , subq_10.metric_time__day AS metric_time__day - , subq_9.listing AS listing - , subq_9.guest AS guest - , subq_9.host AS host - , subq_9.booking__listing AS booking__listing - , subq_9.booking__guest AS booking__guest - , subq_9.booking__host AS booking__host - , subq_9.is_instant AS is_instant - , subq_9.booking__is_instant AS booking__is_instant - , subq_9.bookings AS bookings - , subq_9.instant_bookings AS instant_bookings - , subq_9.booking_value AS booking_value - , subq_9.max_booking_value AS max_booking_value - , subq_9.min_booking_value AS min_booking_value - , subq_9.bookers AS bookers - , subq_9.average_booking_value AS average_booking_value - , subq_9.referred_bookings AS referred_bookings - , subq_9.median_booking_value AS median_booking_value - , subq_9.booking_value_p99 AS booking_value_p99 - , subq_9.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_9.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_9.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_10.ds__day AS ds__day + , subq_10.ds__week AS ds__week + , subq_10.ds__month AS ds__month + , subq_10.ds__quarter AS ds__quarter + , subq_10.ds__year AS ds__year + , subq_10.ds__extract_year AS ds__extract_year + , subq_10.ds__extract_quarter AS ds__extract_quarter + , subq_10.ds__extract_month AS ds__extract_month + , subq_10.ds__extract_day AS ds__extract_day + , subq_10.ds__extract_dow AS ds__extract_dow + , subq_10.ds__extract_doy AS ds__extract_doy + , subq_10.ds_partitioned__day AS ds_partitioned__day + , subq_10.ds_partitioned__week AS ds_partitioned__week + , subq_10.ds_partitioned__month AS ds_partitioned__month + , subq_10.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_10.ds_partitioned__year AS ds_partitioned__year + , subq_10.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_10.paid_at__day AS paid_at__day + , subq_10.paid_at__week AS paid_at__week + , subq_10.paid_at__month AS paid_at__month + , subq_10.paid_at__quarter AS paid_at__quarter + , subq_10.paid_at__year AS paid_at__year + , subq_10.paid_at__extract_year AS paid_at__extract_year + , subq_10.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_10.paid_at__extract_month AS paid_at__extract_month + , subq_10.paid_at__extract_day AS paid_at__extract_day + , subq_10.paid_at__extract_dow AS paid_at__extract_dow + , subq_10.paid_at__extract_doy AS paid_at__extract_doy + , subq_10.booking__ds__day AS booking__ds__day + , subq_10.booking__ds__week AS booking__ds__week + , subq_10.booking__ds__month AS booking__ds__month + , subq_10.booking__ds__quarter AS booking__ds__quarter + , subq_10.booking__ds__year AS booking__ds__year + , subq_10.booking__ds__extract_year AS booking__ds__extract_year + , subq_10.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_10.booking__ds__extract_month AS booking__ds__extract_month + , subq_10.booking__ds__extract_day AS booking__ds__extract_day + , subq_10.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_10.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day AS booking__paid_at__day + , subq_10.booking__paid_at__week AS booking__paid_at__week + , subq_10.booking__paid_at__month AS booking__paid_at__month + , subq_10.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_10.booking__paid_at__year AS booking__paid_at__year + , subq_10.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_10.metric_time__week AS metric_time__week + , subq_10.metric_time__month AS metric_time__month + , subq_10.metric_time__quarter AS metric_time__quarter + , subq_10.metric_time__year AS metric_time__year + , subq_10.metric_time__extract_year AS metric_time__extract_year + , subq_10.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_10.metric_time__extract_month AS metric_time__extract_month + , subq_10.metric_time__extract_day AS metric_time__extract_day + , subq_10.metric_time__extract_dow AS metric_time__extract_dow + , subq_10.metric_time__extract_doy AS metric_time__extract_doy + , subq_13.metric_time__day AS metric_time__day + , subq_10.listing AS listing + , subq_10.guest AS guest + , subq_10.host AS host + , subq_10.booking__listing AS booking__listing + , subq_10.booking__guest AS booking__guest + , subq_10.booking__host AS booking__host + , subq_10.is_instant AS is_instant + , subq_10.booking__is_instant AS booking__is_instant + , subq_10.bookings AS bookings + , subq_10.instant_bookings AS instant_bookings + , subq_10.booking_value AS booking_value + , subq_10.max_booking_value AS max_booking_value + , subq_10.min_booking_value AS min_booking_value + , subq_10.bookers AS bookers + , subq_10.average_booking_value AS average_booking_value + , subq_10.referred_bookings AS referred_bookings + , subq_10.median_booking_value AS median_booking_value + , subq_10.booking_value_p99 AS booking_value_p99 + , subq_10.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_11.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_11 - ) subq_10 + subq_12.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_11 + ) subq_12 + ) subq_13 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -652,18 +696,18 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 + ) subq_9 + ) subq_10 ON - subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - INTERVAL 1 month = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY - subq_13.metric_time__day - ) subq_14 - ) subq_15 + subq_15.metric_time__day + ) subq_16 + ) subq_17 ON - subq_7.metric_time__day = subq_15.metric_time__day + subq_8.metric_time__day = subq_17.metric_time__day GROUP BY - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) -) subq_16 + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) +) subq_18 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index cc78d4892..3be3f783e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -9,18 +9,18 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) AS metric_time__day - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_32.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__day, subq_36.metric_time__day) AS metric_time__day + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_36.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_20.ds AS metric_time__day - , SUM(subq_18.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_20.bookings) AS month_start_bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -28,21 +28,21 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_18 + ) subq_20 ON - DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = subq_20.metric_time__day GROUP BY - subq_20.ds - ) subq_24 + time_spine_src_28006.ds + ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_28.ds AS metric_time__day - , SUM(subq_26.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_28 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_29.bookings) AS bookings_1_month_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -50,14 +50,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + time_spine_src_28006.ds - INTERVAL 1 month = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + time_spine_src_28006.ds + ) subq_36 ON - subq_24.metric_time__day = subq_32.metric_time__day + subq_27.metric_time__day = subq_36.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) -) subq_33 + COALESCE(subq_27.metric_time__day, subq_36.metric_time__day) +) subq_37 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index afc7ce651..91c98ad53 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_16.metric_time__year + subq_18.metric_time__year , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__year, subq_15.metric_time__year) AS metric_time__year - , MAX(subq_7.month_start_bookings) AS month_start_bookings - , MAX(subq_15.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_8.metric_time__year, subq_17.metric_time__year) AS metric_time__year + , MAX(subq_8.month_start_bookings) AS month_start_bookings + , MAX(subq_17.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__year - , subq_6.bookings AS month_start_bookings + subq_7.metric_time__year + , subq_7.bookings AS month_start_bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__year - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__year + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__year'] SELECT - subq_4.metric_time__year - , subq_4.bookings + subq_5.metric_time__year + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -105,8 +105,8 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__year AS metric_time__year + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__year AS metric_time__year , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -129,12 +129,36 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__year'] SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('year', subq_3.ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -331,238 +355,262 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - WHERE subq_2.metric_time__year = subq_2.metric_time__day - ) subq_4 - ) subq_5 + DATE_TRUNC('month', subq_4.metric_time__day) = subq_1.metric_time__day + WHERE subq_4.metric_time__year = subq_4.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__year - ) subq_6 - ) subq_7 + subq_6.metric_time__year + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_14.metric_time__year - , subq_14.bookings AS bookings_1_month_ago + subq_16.metric_time__year + , subq_16.bookings AS bookings_1_month_ago FROM ( -- Aggregate Measures SELECT - subq_13.metric_time__year - , SUM(subq_13.bookings) AS bookings + subq_15.metric_time__year + , SUM(subq_15.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__year'] SELECT - subq_12.metric_time__year - , subq_12.bookings + subq_14.metric_time__year + , subq_14.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_9.ds__day AS ds__day - , subq_9.ds__week AS ds__week - , subq_9.ds__month AS ds__month - , subq_9.ds__quarter AS ds__quarter - , subq_9.ds__year AS ds__year - , subq_9.ds__extract_year AS ds__extract_year - , subq_9.ds__extract_quarter AS ds__extract_quarter - , subq_9.ds__extract_month AS ds__extract_month - , subq_9.ds__extract_day AS ds__extract_day - , subq_9.ds__extract_dow AS ds__extract_dow - , subq_9.ds__extract_doy AS ds__extract_doy - , subq_9.ds_partitioned__day AS ds_partitioned__day - , subq_9.ds_partitioned__week AS ds_partitioned__week - , subq_9.ds_partitioned__month AS ds_partitioned__month - , subq_9.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_9.ds_partitioned__year AS ds_partitioned__year - , subq_9.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_9.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_9.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_9.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_9.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_9.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_9.paid_at__day AS paid_at__day - , subq_9.paid_at__week AS paid_at__week - , subq_9.paid_at__month AS paid_at__month - , subq_9.paid_at__quarter AS paid_at__quarter - , subq_9.paid_at__year AS paid_at__year - , subq_9.paid_at__extract_year AS paid_at__extract_year - , subq_9.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_9.paid_at__extract_month AS paid_at__extract_month - , subq_9.paid_at__extract_day AS paid_at__extract_day - , subq_9.paid_at__extract_dow AS paid_at__extract_dow - , subq_9.paid_at__extract_doy AS paid_at__extract_doy - , subq_9.booking__ds__day AS booking__ds__day - , subq_9.booking__ds__week AS booking__ds__week - , subq_9.booking__ds__month AS booking__ds__month - , subq_9.booking__ds__quarter AS booking__ds__quarter - , subq_9.booking__ds__year AS booking__ds__year - , subq_9.booking__ds__extract_year AS booking__ds__extract_year - , subq_9.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_9.booking__ds__extract_month AS booking__ds__extract_month - , subq_9.booking__ds__extract_day AS booking__ds__extract_day - , subq_9.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_9.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_9.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_9.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_9.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_9.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_9.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_9.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_9.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_9.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_9.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_9.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_9.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_9.booking__paid_at__day AS booking__paid_at__day - , subq_9.booking__paid_at__week AS booking__paid_at__week - , subq_9.booking__paid_at__month AS booking__paid_at__month - , subq_9.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_9.booking__paid_at__year AS booking__paid_at__year - , subq_9.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_9.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_9.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_9.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_9.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_9.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_9.metric_time__week AS metric_time__week - , subq_9.metric_time__month AS metric_time__month - , subq_9.metric_time__quarter AS metric_time__quarter - , subq_9.metric_time__extract_year AS metric_time__extract_year - , subq_9.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_9.metric_time__extract_month AS metric_time__extract_month - , subq_9.metric_time__extract_day AS metric_time__extract_day - , subq_9.metric_time__extract_dow AS metric_time__extract_dow - , subq_9.metric_time__extract_doy AS metric_time__extract_doy - , subq_10.metric_time__day AS metric_time__day - , subq_10.metric_time__year AS metric_time__year - , subq_9.listing AS listing - , subq_9.guest AS guest - , subq_9.host AS host - , subq_9.booking__listing AS booking__listing - , subq_9.booking__guest AS booking__guest - , subq_9.booking__host AS booking__host - , subq_9.is_instant AS is_instant - , subq_9.booking__is_instant AS booking__is_instant - , subq_9.bookings AS bookings - , subq_9.instant_bookings AS instant_bookings - , subq_9.booking_value AS booking_value - , subq_9.max_booking_value AS max_booking_value - , subq_9.min_booking_value AS min_booking_value - , subq_9.bookers AS bookers - , subq_9.average_booking_value AS average_booking_value - , subq_9.referred_bookings AS referred_bookings - , subq_9.median_booking_value AS median_booking_value - , subq_9.booking_value_p99 AS booking_value_p99 - , subq_9.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_9.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_9.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_10.ds__day AS ds__day + , subq_10.ds__week AS ds__week + , subq_10.ds__month AS ds__month + , subq_10.ds__quarter AS ds__quarter + , subq_10.ds__year AS ds__year + , subq_10.ds__extract_year AS ds__extract_year + , subq_10.ds__extract_quarter AS ds__extract_quarter + , subq_10.ds__extract_month AS ds__extract_month + , subq_10.ds__extract_day AS ds__extract_day + , subq_10.ds__extract_dow AS ds__extract_dow + , subq_10.ds__extract_doy AS ds__extract_doy + , subq_10.ds_partitioned__day AS ds_partitioned__day + , subq_10.ds_partitioned__week AS ds_partitioned__week + , subq_10.ds_partitioned__month AS ds_partitioned__month + , subq_10.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_10.ds_partitioned__year AS ds_partitioned__year + , subq_10.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_10.paid_at__day AS paid_at__day + , subq_10.paid_at__week AS paid_at__week + , subq_10.paid_at__month AS paid_at__month + , subq_10.paid_at__quarter AS paid_at__quarter + , subq_10.paid_at__year AS paid_at__year + , subq_10.paid_at__extract_year AS paid_at__extract_year + , subq_10.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_10.paid_at__extract_month AS paid_at__extract_month + , subq_10.paid_at__extract_day AS paid_at__extract_day + , subq_10.paid_at__extract_dow AS paid_at__extract_dow + , subq_10.paid_at__extract_doy AS paid_at__extract_doy + , subq_10.booking__ds__day AS booking__ds__day + , subq_10.booking__ds__week AS booking__ds__week + , subq_10.booking__ds__month AS booking__ds__month + , subq_10.booking__ds__quarter AS booking__ds__quarter + , subq_10.booking__ds__year AS booking__ds__year + , subq_10.booking__ds__extract_year AS booking__ds__extract_year + , subq_10.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_10.booking__ds__extract_month AS booking__ds__extract_month + , subq_10.booking__ds__extract_day AS booking__ds__extract_day + , subq_10.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_10.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day AS booking__paid_at__day + , subq_10.booking__paid_at__week AS booking__paid_at__week + , subq_10.booking__paid_at__month AS booking__paid_at__month + , subq_10.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_10.booking__paid_at__year AS booking__paid_at__year + , subq_10.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_10.metric_time__week AS metric_time__week + , subq_10.metric_time__month AS metric_time__month + , subq_10.metric_time__quarter AS metric_time__quarter + , subq_10.metric_time__extract_year AS metric_time__extract_year + , subq_10.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_10.metric_time__extract_month AS metric_time__extract_month + , subq_10.metric_time__extract_day AS metric_time__extract_day + , subq_10.metric_time__extract_dow AS metric_time__extract_dow + , subq_10.metric_time__extract_doy AS metric_time__extract_doy + , subq_13.metric_time__day AS metric_time__day + , subq_13.metric_time__year AS metric_time__year + , subq_10.listing AS listing + , subq_10.guest AS guest + , subq_10.host AS host + , subq_10.booking__listing AS booking__listing + , subq_10.booking__guest AS booking__guest + , subq_10.booking__host AS booking__host + , subq_10.is_instant AS is_instant + , subq_10.booking__is_instant AS booking__is_instant + , subq_10.bookings AS bookings + , subq_10.instant_bookings AS instant_bookings + , subq_10.booking_value AS booking_value + , subq_10.max_booking_value AS max_booking_value + , subq_10.min_booking_value AS min_booking_value + , subq_10.bookers AS bookers + , subq_10.average_booking_value AS average_booking_value + , subq_10.referred_bookings AS referred_bookings + , subq_10.median_booking_value AS median_booking_value + , subq_10.booking_value_p99 AS booking_value_p99 + , subq_10.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__year'] SELECT - subq_11.ds AS metric_time__day - , DATE_TRUNC('year', subq_11.ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_11 - ) subq_10 + subq_12.metric_time__day + , subq_12.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__day + , subq_11.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_11 + ) subq_12 + ) subq_13 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -655,18 +703,18 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 + ) subq_9 + ) subq_10 ON - subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - INTERVAL 1 month = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY - subq_13.metric_time__year - ) subq_14 - ) subq_15 + subq_15.metric_time__year + ) subq_16 + ) subq_17 ON - subq_7.metric_time__year = subq_15.metric_time__year + subq_8.metric_time__year = subq_17.metric_time__year GROUP BY - COALESCE(subq_7.metric_time__year, subq_15.metric_time__year) -) subq_16 + COALESCE(subq_8.metric_time__year, subq_17.metric_time__year) +) subq_18 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index b31f53052..d46a8c2a7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -9,18 +9,18 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__year, subq_32.metric_time__year) AS metric_time__year - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_32.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__year, subq_36.metric_time__year) AS metric_time__year + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_36.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__year'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', subq_20.ds) AS metric_time__year - , SUM(subq_18.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + , SUM(subq_20.bookings) AS month_start_bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -28,22 +28,22 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_18 + ) subq_20 ON - DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day - WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = subq_20.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds GROUP BY - DATE_TRUNC('year', subq_20.ds) - ) subq_24 + DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__year'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', subq_28.ds) AS metric_time__year - , SUM(subq_26.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_28 + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + , SUM(subq_29.bookings) AS bookings_1_month_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -51,14 +51,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + time_spine_src_28006.ds - INTERVAL 1 month = subq_29.metric_time__day GROUP BY - DATE_TRUNC('year', subq_28.ds) - ) subq_32 + DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_36 ON - subq_24.metric_time__year = subq_32.metric_time__year + subq_27.metric_time__year = subq_36.metric_time__year GROUP BY - COALESCE(subq_24.metric_time__year, subq_32.metric_time__year) -) subq_33 + COALESCE(subq_27.metric_time__year, subq_36.metric_time__year) +) subq_37 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index e88a2f9f3..f5b3979e4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day + subq_16.metric_time__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_5.metric_time__day, subq_14.metric_time__day) AS metric_time__day + COALESCE(subq_5.metric_time__day, subq_15.metric_time__day) AS metric_time__day , MAX(subq_5.bookings) AS bookings - , MAX(subq_14.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_15.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -333,119 +333,119 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day - , subq_13.bookings AS bookings_2_weeks_ago + subq_14.metric_time__day + , subq_14.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_12.metric_time__day - , SUM(subq_12.bookings) AS bookings + subq_13.metric_time__day + , SUM(subq_13.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_11.metric_time__day - , subq_11.bookings + subq_12.metric_time__day + , subq_12.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_10.metric_time__day - , subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.ds_partitioned__day - , subq_10.ds_partitioned__week - , subq_10.ds_partitioned__month - , subq_10.ds_partitioned__quarter - , subq_10.ds_partitioned__year - , subq_10.ds_partitioned__extract_year - , subq_10.ds_partitioned__extract_quarter - , subq_10.ds_partitioned__extract_month - , subq_10.ds_partitioned__extract_day - , subq_10.ds_partitioned__extract_dow - , subq_10.ds_partitioned__extract_doy - , subq_10.paid_at__day - , subq_10.paid_at__week - , subq_10.paid_at__month - , subq_10.paid_at__quarter - , subq_10.paid_at__year - , subq_10.paid_at__extract_year - , subq_10.paid_at__extract_quarter - , subq_10.paid_at__extract_month - , subq_10.paid_at__extract_day - , subq_10.paid_at__extract_dow - , subq_10.paid_at__extract_doy - , subq_10.booking__ds__day - , subq_10.booking__ds__week - , subq_10.booking__ds__month - , subq_10.booking__ds__quarter - , subq_10.booking__ds__year - , subq_10.booking__ds__extract_year - , subq_10.booking__ds__extract_quarter - , subq_10.booking__ds__extract_month - , subq_10.booking__ds__extract_day - , subq_10.booking__ds__extract_dow - , subq_10.booking__ds__extract_doy - , subq_10.booking__ds_partitioned__day - , subq_10.booking__ds_partitioned__week - , subq_10.booking__ds_partitioned__month - , subq_10.booking__ds_partitioned__quarter - , subq_10.booking__ds_partitioned__year - , subq_10.booking__ds_partitioned__extract_year - , subq_10.booking__ds_partitioned__extract_quarter - , subq_10.booking__ds_partitioned__extract_month - , subq_10.booking__ds_partitioned__extract_day - , subq_10.booking__ds_partitioned__extract_dow - , subq_10.booking__ds_partitioned__extract_doy - , subq_10.booking__paid_at__day - , subq_10.booking__paid_at__week - , subq_10.booking__paid_at__month - , subq_10.booking__paid_at__quarter - , subq_10.booking__paid_at__year - , subq_10.booking__paid_at__extract_year - , subq_10.booking__paid_at__extract_quarter - , subq_10.booking__paid_at__extract_month - , subq_10.booking__paid_at__extract_day - , subq_10.booking__paid_at__extract_dow - , subq_10.booking__paid_at__extract_doy - , subq_10.metric_time__week - , subq_10.metric_time__month - , subq_10.metric_time__quarter - , subq_10.metric_time__year - , subq_10.metric_time__extract_year - , subq_10.metric_time__extract_quarter - , subq_10.metric_time__extract_month - , subq_10.metric_time__extract_day - , subq_10.metric_time__extract_dow - , subq_10.metric_time__extract_doy - , subq_10.listing - , subq_10.guest - , subq_10.host - , subq_10.booking__listing - , subq_10.booking__guest - , subq_10.booking__host - , subq_10.is_instant - , subq_10.booking__is_instant - , subq_10.bookings - , subq_10.instant_bookings - , subq_10.booking_value - , subq_10.max_booking_value - , subq_10.min_booking_value - , subq_10.bookers - , subq_10.average_booking_value - , subq_10.referred_bookings - , subq_10.median_booking_value - , subq_10.booking_value_p99 - , subq_10.discrete_booking_value_p99 - , subq_10.approximate_continuous_booking_value_p99 - , subq_10.approximate_discrete_booking_value_p99 + subq_11.ds__day + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , subq_11.ds__year + , subq_11.ds__extract_year + , subq_11.ds__extract_quarter + , subq_11.ds__extract_month + , subq_11.ds__extract_day + , subq_11.ds__extract_dow + , subq_11.ds__extract_doy + , subq_11.ds_partitioned__day + , subq_11.ds_partitioned__week + , subq_11.ds_partitioned__month + , subq_11.ds_partitioned__quarter + , subq_11.ds_partitioned__year + , subq_11.ds_partitioned__extract_year + , subq_11.ds_partitioned__extract_quarter + , subq_11.ds_partitioned__extract_month + , subq_11.ds_partitioned__extract_day + , subq_11.ds_partitioned__extract_dow + , subq_11.ds_partitioned__extract_doy + , subq_11.paid_at__day + , subq_11.paid_at__week + , subq_11.paid_at__month + , subq_11.paid_at__quarter + , subq_11.paid_at__year + , subq_11.paid_at__extract_year + , subq_11.paid_at__extract_quarter + , subq_11.paid_at__extract_month + , subq_11.paid_at__extract_day + , subq_11.paid_at__extract_dow + , subq_11.paid_at__extract_doy + , subq_11.booking__ds__day + , subq_11.booking__ds__week + , subq_11.booking__ds__month + , subq_11.booking__ds__quarter + , subq_11.booking__ds__year + , subq_11.booking__ds__extract_year + , subq_11.booking__ds__extract_quarter + , subq_11.booking__ds__extract_month + , subq_11.booking__ds__extract_day + , subq_11.booking__ds__extract_dow + , subq_11.booking__ds__extract_doy + , subq_11.booking__ds_partitioned__day + , subq_11.booking__ds_partitioned__week + , subq_11.booking__ds_partitioned__month + , subq_11.booking__ds_partitioned__quarter + , subq_11.booking__ds_partitioned__year + , subq_11.booking__ds_partitioned__extract_year + , subq_11.booking__ds_partitioned__extract_quarter + , subq_11.booking__ds_partitioned__extract_month + , subq_11.booking__ds_partitioned__extract_day + , subq_11.booking__ds_partitioned__extract_dow + , subq_11.booking__ds_partitioned__extract_doy + , subq_11.booking__paid_at__day + , subq_11.booking__paid_at__week + , subq_11.booking__paid_at__month + , subq_11.booking__paid_at__quarter + , subq_11.booking__paid_at__year + , subq_11.booking__paid_at__extract_year + , subq_11.booking__paid_at__extract_quarter + , subq_11.booking__paid_at__extract_month + , subq_11.booking__paid_at__extract_day + , subq_11.booking__paid_at__extract_dow + , subq_11.booking__paid_at__extract_doy + , subq_11.metric_time__week + , subq_11.metric_time__month + , subq_11.metric_time__quarter + , subq_11.metric_time__year + , subq_11.metric_time__extract_year + , subq_11.metric_time__extract_quarter + , subq_11.metric_time__extract_month + , subq_11.metric_time__extract_day + , subq_11.metric_time__extract_dow + , subq_11.metric_time__extract_doy + , subq_11.metric_time__day + , subq_11.listing + , subq_11.guest + , subq_11.host + , subq_11.booking__listing + , subq_11.booking__guest + , subq_11.booking__host + , subq_11.is_instant + , subq_11.booking__is_instant + , subq_11.bookings + , subq_11.instant_bookings + , subq_11.booking_value + , subq_11.max_booking_value + , subq_11.min_booking_value + , subq_11.bookers + , subq_11.average_booking_value + , subq_11.referred_bookings + , subq_11.median_booking_value + , subq_11.booking_value_p99 + , subq_11.discrete_booking_value_p99 + , subq_11.approximate_continuous_booking_value_p99 + , subq_11.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -525,7 +525,7 @@ FROM ( , subq_7.metric_time__extract_day AS metric_time__extract_day , subq_7.metric_time__extract_dow AS metric_time__extract_dow , subq_7.metric_time__extract_doy AS metric_time__extract_doy - , subq_8.metric_time__day AS metric_time__day + , subq_10.metric_time__day AS metric_time__day , subq_7.listing AS listing , subq_7.guest AS guest , subq_7.host AS host @@ -548,11 +548,33 @@ FROM ( , subq_7.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_7.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_9.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_9 - ) subq_8 + subq_9.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_8.ds__day AS metric_time__day + , subq_8.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_8 + ) subq_9 + ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -749,17 +771,17 @@ FROM ( ) subq_6 ) subq_7 ON - subq_8.metric_time__day - INTERVAL 14 day = subq_7.metric_time__day - ) subq_10 + subq_10.metric_time__day - INTERVAL 14 day = subq_7.metric_time__day + ) subq_11 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' - ) subq_11 - ) subq_12 + ) subq_12 + ) subq_13 GROUP BY - subq_12.metric_time__day - ) subq_13 - ) subq_14 + subq_13.metric_time__day + ) subq_14 + ) subq_15 ON - subq_5.metric_time__day = subq_14.metric_time__day + subq_5.metric_time__day = subq_15.metric_time__day GROUP BY - COALESCE(subq_5.metric_time__day, subq_14.metric_time__day) -) subq_15 + COALESCE(subq_5.metric_time__day, subq_15.metric_time__day) +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index 66f5fe7c5..f32446618 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_30.metric_time__day) AS metric_time__day - , MAX(subq_21.bookings) AS bookings - , MAX(subq_30.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_22.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_22.bookings) AS bookings + , MAX(subq_32.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -27,11 +27,11 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_17 + ) subq_18 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_21 + ) subq_22 FULL OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -43,9 +43,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_25.ds AS metric_time__day - , subq_23.bookings AS bookings - FROM ***************************.mf_time_spine subq_25 + time_spine_src_28006.ds AS metric_time__day + , subq_24.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -53,16 +53,16 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_23 + ) subq_24 ON - subq_25.ds - INTERVAL 14 day = subq_23.metric_time__day - ) subq_26 + time_spine_src_28006.ds - INTERVAL 14 day = subq_24.metric_time__day + ) subq_28 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_30 + ) subq_32 ON - subq_21.metric_time__day = subq_30.metric_time__day + subq_22.metric_time__day = subq_32.metric_time__day GROUP BY - COALESCE(subq_21.metric_time__day, subq_30.metric_time__day) -) subq_31 + COALESCE(subq_22.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql index 7a0c96d98..d7fe86960 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day + subq_11.metric_time__day , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day - , subq_9.bookers AS every_2_days_bookers_2_days_ago + subq_10.metric_time__day + , subq_10.bookers AS every_2_days_bookers_2_days_ago FROM ( -- Aggregate Measures SELECT - subq_8.metric_time__day - , COUNT(DISTINCT subq_8.bookers) AS bookers + subq_9.metric_time__day + , COUNT(DISTINCT subq_9.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.bookers + subq_8.metric_time__day + , subq_8.bookers FROM ( -- Join to Time Spine Dataset SELECT @@ -100,7 +100,7 @@ FROM ( , subq_4.metric_time__extract_day AS metric_time__extract_day , subq_4.metric_time__extract_dow AS metric_time__extract_dow , subq_4.metric_time__extract_doy AS metric_time__extract_doy - , subq_5.metric_time__day AS metric_time__day + , subq_7.metric_time__day AS metric_time__day , subq_4.listing AS listing , subq_4.guest AS guest , subq_4.host AS host @@ -123,11 +123,33 @@ FROM ( , subq_4.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_4.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -438,10 +460,10 @@ FROM ( ) ) subq_4 ON - subq_5.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day - ) subq_7 - ) subq_8 + subq_7.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day + ) subq_8 + ) subq_9 GROUP BY - subq_8.metric_time__day - ) subq_9 -) subq_10 + subq_9.metric_time__day + ) subq_10 +) subq_11 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql index 47db02e9d..adf2d6a79 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql @@ -12,26 +12,26 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS metric_time__day - , COUNT(DISTINCT subq_15.bookers) AS every_2_days_bookers_2_days_ago - FROM ***************************.mf_time_spine subq_17 + time_spine_src_28006.ds AS metric_time__day + , COUNT(DISTINCT subq_16.bookers) AS every_2_days_bookers_2_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Join Self Over Time Range SELECT - subq_14.ds AS metric_time__day + subq_15.ds AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - INTERVAL 2 day ) - ) subq_15 + ) subq_16 ON - subq_17.ds - INTERVAL 2 day = subq_15.metric_time__day + time_spine_src_28006.ds - INTERVAL 2 day = subq_16.metric_time__day GROUP BY - subq_17.ds -) subq_21 + time_spine_src_28006.ds +) subq_23 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 5e5ede602..579e062b6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_14.booking__ds__day , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.booking__ds__day, subq_12.booking__ds__day) AS booking__ds__day - , MAX(subq_7.booking_value) AS booking_value - , MAX(subq_12.bookers) AS bookers + COALESCE(subq_8.booking__ds__day, subq_13.booking__ds__day) AS booking__ds__day + , MAX(subq_8.booking_value) AS booking_value + , MAX(subq_13.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_6.booking__ds__day - , subq_6.booking_value + subq_7.booking__ds__day + , subq_7.booking_value FROM ( -- Aggregate Measures SELECT - subq_5.booking__ds__day - , SUM(subq_5.booking_value) AS booking_value + subq_6.booking__ds__day + , SUM(subq_6.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__ds__day'] SELECT - subq_4.booking__ds__day - , subq_4.booking_value + subq_5.booking__ds__day + , subq_5.booking_value FROM ( -- Join to Time Spine Dataset SELECT @@ -106,7 +106,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.booking__ds__day AS booking__ds__day + , subq_4.booking__ds__day AS booking__ds__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -129,11 +129,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['booking__ds__day', 'booking__ds__day'] SELECT - subq_3.ds AS booking__ds__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.booking__ds__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS booking__ds__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,129 +352,129 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.booking__ds__day - INTERVAL 1 week = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + subq_4.booking__ds__day - INTERVAL 1 week = subq_1.booking__ds__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.booking__ds__day - ) subq_6 - ) subq_7 + subq_6.booking__ds__day + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.booking__ds__day - , subq_11.bookers + subq_12.booking__ds__day + , subq_12.bookers FROM ( -- Aggregate Measures SELECT - subq_10.booking__ds__day - , COUNT(DISTINCT subq_10.bookers) AS bookers + subq_11.booking__ds__day + , COUNT(DISTINCT subq_11.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'booking__ds__day'] SELECT - subq_9.booking__ds__day - , subq_9.bookers + subq_10.booking__ds__day + , subq_10.bookers FROM ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -545,15 +567,15 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 - ) subq_10 + ) subq_9 + ) subq_10 + ) subq_11 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_11.booking__ds__day + ) subq_12 + ) subq_13 ON - subq_7.booking__ds__day = subq_12.booking__ds__day + subq_8.booking__ds__day = subq_13.booking__ds__day GROUP BY - COALESCE(subq_7.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_8.booking__ds__day, subq_13.booking__ds__day) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index d916d9e53..8a8f9c46d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql @@ -9,25 +9,25 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.booking__ds__day, subq_26.booking__ds__day) AS booking__ds__day - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_26.bookers) AS bookers + COALESCE(subq_23.booking__ds__day, subq_28.booking__ds__day) AS booking__ds__day + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_28.bookers) AS bookers FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['booking_value', 'booking__ds__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(bookings_source_src_28000.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_17.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + time_spine_src_28006.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - ) subq_21 + time_spine_src_28006.ds + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -40,9 +40,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_26 + ) subq_28 ON - subq_21.booking__ds__day = subq_26.booking__ds__day + subq_23.booking__ds__day = subq_28.booking__ds__day GROUP BY - COALESCE(subq_21.booking__ds__day, subq_26.booking__ds__day) -) subq_27 + COALESCE(subq_23.booking__ds__day, subq_28.booking__ds__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql index 6cc7df6c9..bcca782ca 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_8.metric_time__day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings AS bookings_5_days_ago + subq_7.metric_time__day + , subq_7.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -100,7 +100,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -123,11 +123,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -324,10 +346,10 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 -) subq_7 + subq_6.metric_time__day + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index 4a3f73bad..9de842c71 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql @@ -12,9 +12,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ds AS metric_time__day - , SUM(subq_9.bookings) AS bookings_5_days_ago - FROM ***************************.mf_time_spine subq_11 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_10.bookings) AS bookings_5_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -22,9 +22,9 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 ON - subq_11.ds - INTERVAL 5 day = subq_9.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_10.metric_time__day GROUP BY - subq_11.ds -) subq_15 + time_spine_src_28006.ds +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 9c0bdbd42..2dc8c3744 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_15.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Pass Only Elements: ['metric_time__day', 'bookings_offset_once'] SELECT - subq_12.metric_time__day - , subq_12.bookings_offset_once + subq_14.metric_time__day + , subq_14.bookings_offset_once FROM ( -- Constrain Output with WHERE SELECT - subq_11.metric_time__day - , subq_11.booking__is_instant - , subq_11.bookings_offset_once + subq_13.metric_time__day + , subq_13.booking__is_instant + , subq_13.bookings_offset_once FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.booking__is_instant AS booking__is_instant - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.booking__is_instant AS booking__is_instant + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_10.ds__day AS metric_time__day + , subq_10.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_10 + ) subq_11 + ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.booking__is_instant + subq_8.metric_time__day + , subq_8.booking__is_instant , 2 * bookings AS bookings_offset_once FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.booking__is_instant - , subq_6.bookings + subq_7.metric_time__day + , subq_7.booking__is_instant + , subq_7.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.booking__is_instant - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , subq_6.booking__is_instant + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.booking__is_instant - , subq_4.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -132,7 +154,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -155,11 +177,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -356,18 +400,18 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - , subq_5.booking__is_instant - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + , subq_6.booking__is_instant + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day - ) subq_11 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day + ) subq_13 WHERE booking__is_instant - ) subq_12 -) subq_13 + ) subq_14 +) subq_15 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index d62752cb4..42b724326 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql @@ -15,10 +15,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_24.ds AS metric_time__day - , subq_22.booking__is_instant AS booking__is_instant - , subq_22.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_24 + time_spine_src_28006.ds 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 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -31,10 +31,10 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS metric_time__day - , subq_15.booking__is_instant AS booking__is_instant - , SUM(subq_15.bookings) AS bookings - FROM ***************************.mf_time_spine subq_17 + time_spine_src_28006.ds 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 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -43,16 +43,16 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + ) subq_17 ON - subq_17.ds - INTERVAL 5 day = subq_15.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_17.metric_time__day GROUP BY - subq_17.ds - , subq_15.booking__is_instant - ) subq_21 - ) subq_22 + time_spine_src_28006.ds + , subq_17.booking__is_instant + ) subq_24 + ) subq_25 ON - subq_24.ds - INTERVAL 2 day = subq_22.metric_time__day - ) subq_25 + time_spine_src_28006.ds - INTERVAL 2 day = subq_25.metric_time__day + ) subq_29 WHERE booking__is_instant -) subq_27 +) subq_31 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index 968a86830..6574468fc 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day + subq_16.metric_time__day , booking_fees - booking_fees_start_of_month AS booking_fees_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_8.metric_time__day, subq_14.metric_time__day) AS metric_time__day - , MAX(subq_8.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_14.booking_fees) AS booking_fees + COALESCE(subq_9.metric_time__day, subq_15.metric_time__day) AS metric_time__day + , MAX(subq_9.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_15.booking_fees) AS booking_fees FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_5.booking_fees_start_of_month AS booking_fees_start_of_month FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_6 + ) subq_7 + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -245,129 +267,129 @@ FROM ( ) subq_4 ) subq_5 ON - DATE_TRUNC('month', subq_6.metric_time__day) = subq_5.metric_time__day - ) subq_8 + DATE_TRUNC('month', subq_8.metric_time__day) = subq_5.metric_time__day + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_14.metric_time__day , booking_value * 0.05 AS booking_fees FROM ( -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , subq_12.booking_value + subq_13.metric_time__day + , subq_13.booking_value FROM ( -- Aggregate Measures SELECT - subq_11.metric_time__day - , SUM(subq_11.booking_value) AS booking_value + subq_12.metric_time__day + , SUM(subq_12.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_11.metric_time__day + , subq_11.booking_value FROM ( -- Metric Time Dimension 'ds' SELECT - subq_9.ds__day - , subq_9.ds__week - , subq_9.ds__month - , subq_9.ds__quarter - , subq_9.ds__year - , subq_9.ds__extract_year - , subq_9.ds__extract_quarter - , subq_9.ds__extract_month - , subq_9.ds__extract_day - , subq_9.ds__extract_dow - , subq_9.ds__extract_doy - , subq_9.ds_partitioned__day - , subq_9.ds_partitioned__week - , subq_9.ds_partitioned__month - , subq_9.ds_partitioned__quarter - , subq_9.ds_partitioned__year - , subq_9.ds_partitioned__extract_year - , subq_9.ds_partitioned__extract_quarter - , subq_9.ds_partitioned__extract_month - , subq_9.ds_partitioned__extract_day - , subq_9.ds_partitioned__extract_dow - , subq_9.ds_partitioned__extract_doy - , subq_9.paid_at__day - , subq_9.paid_at__week - , subq_9.paid_at__month - , subq_9.paid_at__quarter - , subq_9.paid_at__year - , subq_9.paid_at__extract_year - , subq_9.paid_at__extract_quarter - , subq_9.paid_at__extract_month - , subq_9.paid_at__extract_day - , subq_9.paid_at__extract_dow - , subq_9.paid_at__extract_doy - , subq_9.booking__ds__day - , subq_9.booking__ds__week - , subq_9.booking__ds__month - , subq_9.booking__ds__quarter - , subq_9.booking__ds__year - , subq_9.booking__ds__extract_year - , subq_9.booking__ds__extract_quarter - , subq_9.booking__ds__extract_month - , subq_9.booking__ds__extract_day - , subq_9.booking__ds__extract_dow - , subq_9.booking__ds__extract_doy - , subq_9.booking__ds_partitioned__day - , subq_9.booking__ds_partitioned__week - , subq_9.booking__ds_partitioned__month - , subq_9.booking__ds_partitioned__quarter - , subq_9.booking__ds_partitioned__year - , subq_9.booking__ds_partitioned__extract_year - , subq_9.booking__ds_partitioned__extract_quarter - , subq_9.booking__ds_partitioned__extract_month - , subq_9.booking__ds_partitioned__extract_day - , subq_9.booking__ds_partitioned__extract_dow - , subq_9.booking__ds_partitioned__extract_doy - , subq_9.booking__paid_at__day - , subq_9.booking__paid_at__week - , subq_9.booking__paid_at__month - , subq_9.booking__paid_at__quarter - , subq_9.booking__paid_at__year - , subq_9.booking__paid_at__extract_year - , subq_9.booking__paid_at__extract_quarter - , subq_9.booking__paid_at__extract_month - , subq_9.booking__paid_at__extract_day - , subq_9.booking__paid_at__extract_dow - , subq_9.booking__paid_at__extract_doy - , subq_9.ds__day AS metric_time__day - , subq_9.ds__week AS metric_time__week - , subq_9.ds__month AS metric_time__month - , subq_9.ds__quarter AS metric_time__quarter - , subq_9.ds__year AS metric_time__year - , subq_9.ds__extract_year AS metric_time__extract_year - , subq_9.ds__extract_quarter AS metric_time__extract_quarter - , subq_9.ds__extract_month AS metric_time__extract_month - , subq_9.ds__extract_day AS metric_time__extract_day - , subq_9.ds__extract_dow AS metric_time__extract_dow - , subq_9.ds__extract_doy AS metric_time__extract_doy - , subq_9.listing - , subq_9.guest - , subq_9.host - , subq_9.booking__listing - , subq_9.booking__guest - , subq_9.booking__host - , subq_9.is_instant - , subq_9.booking__is_instant - , subq_9.bookings - , subq_9.instant_bookings - , subq_9.booking_value - , subq_9.max_booking_value - , subq_9.min_booking_value - , subq_9.bookers - , subq_9.average_booking_value - , subq_9.referred_bookings - , subq_9.median_booking_value - , subq_9.booking_value_p99 - , subq_9.discrete_booking_value_p99 - , subq_9.approximate_continuous_booking_value_p99 - , subq_9.approximate_discrete_booking_value_p99 + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -460,16 +482,16 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_10 + ) subq_11 + ) subq_12 GROUP BY - subq_11.metric_time__day - ) subq_12 - ) subq_13 - ) subq_14 + subq_12.metric_time__day + ) subq_13 + ) subq_14 + ) subq_15 ON - subq_8.metric_time__day = subq_14.metric_time__day + subq_9.metric_time__day = subq_15.metric_time__day GROUP BY - COALESCE(subq_8.metric_time__day, subq_14.metric_time__day) -) subq_15 + COALESCE(subq_9.metric_time__day, subq_15.metric_time__day) +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 101e623ab..37b1d7d77 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql @@ -9,15 +9,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_30.metric_time__day) AS metric_time__day - , MAX(subq_24.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_30.booking_fees) AS booking_fees + COALESCE(subq_26.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_26.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_32.booking_fees) AS booking_fees FROM ( -- Join to Time Spine Dataset SELECT - subq_23.ds AS metric_time__day - , subq_21.booking_fees_start_of_month AS booking_fees_start_of_month - FROM ***************************.mf_time_spine subq_23 + time_spine_src_28006.ds AS metric_time__day + , subq_22.booking_fees_start_of_month AS booking_fees_start_of_month + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -35,11 +35,11 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_20 - ) subq_21 + ) subq_21 + ) subq_22 ON - DATE_TRUNC('month', subq_23.ds) = subq_21.metric_time__day - ) subq_24 + DATE_TRUNC('month', time_spine_src_28006.ds) = subq_22.metric_time__day + ) subq_26 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT @@ -57,10 +57,10 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_29 - ) subq_30 + ) subq_31 + ) subq_32 ON - subq_24.metric_time__day = subq_30.metric_time__day + subq_26.metric_time__day = subq_32.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_30.metric_time__day) -) subq_31 + COALESCE(subq_26.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql index b3f4befad..9d009a63e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day + subq_13.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_10.ds__day AS metric_time__day + , subq_10.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_10 + ) subq_11 + ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_8.metric_time__day , 2 * bookings AS bookings_offset_once FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_7.metric_time__day + , subq_7.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -116,7 +138,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -139,11 +161,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -340,14 +384,14 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day -) subq_11 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql index ec796be86..fe15c86bd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_22.ds AS metric_time__day - , subq_20.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_22 + time_spine_src_28006.ds AS metric_time__day + , subq_23.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -23,9 +23,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_15.ds AS metric_time__day - , SUM(subq_13.bookings) AS bookings - FROM ***************************.mf_time_spine subq_15 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_15.bookings) AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -33,13 +33,13 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_15 ON - subq_15.ds - INTERVAL 5 day = subq_13.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - subq_22.ds - INTERVAL 2 day = subq_20.metric_time__day -) subq_23 + time_spine_src_28006.ds - INTERVAL 2 day = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql index a71976971..bdad0167e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day + subq_14.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - subq_11.metric_time__day - , subq_11.bookings_offset_once + subq_13.metric_time__day + , subq_13.bookings_offset_once FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_10.ds__day AS metric_time__day + , subq_10.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_10 + ) subq_11 + ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_8.metric_time__day , 2 * bookings AS bookings_offset_once FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_7.metric_time__day + , subq_7.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -121,7 +143,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -144,11 +166,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +389,16 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day - ) subq_11 - WHERE subq_11.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' -) subq_12 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day + ) subq_13 + WHERE subq_13.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 457a8a18d..6a16e0902 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql @@ -10,9 +10,9 @@ FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - subq_23.ds AS metric_time__day - , subq_21.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_23 + time_spine_src_28006.ds AS metric_time__day + , subq_24.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -24,9 +24,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_16.ds AS metric_time__day - , SUM(subq_14.bookings) AS bookings - FROM ***************************.mf_time_spine subq_16 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_16.bookings) AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -34,14 +34,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_16 ON - subq_16.ds - INTERVAL 5 day = subq_14.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - subq_23.ds - INTERVAL 2 day = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + time_spine_src_28006.ds - INTERVAL 2 day = subq_24.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql index 1645b0527..dce7677f8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day + subq_14.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE SELECT - subq_11.metric_time__day - , subq_11.bookings_offset_once + subq_13.metric_time__day + , subq_13.bookings_offset_once FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_10.ds__day AS metric_time__day + , subq_10.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_10 + ) subq_11 + ) subq_12 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_8.metric_time__day , 2 * bookings AS bookings_offset_once FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_7.metric_time__day + , subq_7.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -121,7 +143,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -144,11 +166,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +389,16 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day - ) subq_11 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day + ) subq_13 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' -) subq_12 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 5d979eb0c..c25d4f0b9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql @@ -14,9 +14,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_23.ds AS metric_time__day - , subq_21.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_23 + time_spine_src_28006.ds AS metric_time__day + , subq_24.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -28,9 +28,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_16.ds AS metric_time__day - , SUM(subq_14.bookings) AS bookings - FROM ***************************.mf_time_spine subq_16 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_16.bookings) AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -38,15 +38,15 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_16 ON - subq_16.ds - INTERVAL 5 day = subq_14.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - subq_23.ds - INTERVAL 2 day = subq_21.metric_time__day - ) subq_24 + time_spine_src_28006.ds - 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_25 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 470dd41cc..438068b20 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__month + subq_9.metric_time__month , bookings_start_of_month AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__month - , subq_7.bookings AS bookings_start_of_month + subq_8.metric_time__month + , subq_8.bookings AS bookings_start_of_month FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__month - , SUM(subq_6.bookings) AS bookings + subq_7.metric_time__month + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__month'] SELECT - subq_5.metric_time__month - , subq_5.bookings + subq_6.metric_time__month + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.ds__day - , subq_4.ds__week - , subq_4.ds__month - , subq_4.ds__quarter - , subq_4.ds__year - , subq_4.ds__extract_year - , subq_4.ds__extract_quarter - , subq_4.ds__extract_month - , subq_4.ds__extract_day - , subq_4.ds__extract_dow - , subq_4.ds__extract_doy - , subq_4.ds_partitioned__day - , subq_4.ds_partitioned__week - , subq_4.ds_partitioned__month - , subq_4.ds_partitioned__quarter - , subq_4.ds_partitioned__year - , subq_4.ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy - , subq_4.paid_at__day - , subq_4.paid_at__week - , subq_4.paid_at__month - , subq_4.paid_at__quarter - , subq_4.paid_at__year - , subq_4.paid_at__extract_year - , subq_4.paid_at__extract_quarter - , subq_4.paid_at__extract_month - , subq_4.paid_at__extract_day - , subq_4.paid_at__extract_dow - , subq_4.paid_at__extract_doy - , subq_4.booking__ds__day - , subq_4.booking__ds__week - , subq_4.booking__ds__month - , subq_4.booking__ds__quarter - , subq_4.booking__ds__year - , subq_4.booking__ds__extract_year - , subq_4.booking__ds__extract_quarter - , subq_4.booking__ds__extract_month - , subq_4.booking__ds__extract_day - , subq_4.booking__ds__extract_dow - , subq_4.booking__ds__extract_doy - , subq_4.booking__ds_partitioned__day - , subq_4.booking__ds_partitioned__week - , subq_4.booking__ds_partitioned__month - , subq_4.booking__ds_partitioned__quarter - , subq_4.booking__ds_partitioned__year - , subq_4.booking__ds_partitioned__extract_year - , subq_4.booking__ds_partitioned__extract_quarter - , subq_4.booking__ds_partitioned__extract_month - , subq_4.booking__ds_partitioned__extract_day - , subq_4.booking__ds_partitioned__extract_dow - , subq_4.booking__ds_partitioned__extract_doy - , subq_4.booking__paid_at__day - , subq_4.booking__paid_at__week - , subq_4.booking__paid_at__month - , subq_4.booking__paid_at__quarter - , subq_4.booking__paid_at__year - , subq_4.booking__paid_at__extract_year - , subq_4.booking__paid_at__extract_quarter - , subq_4.booking__paid_at__extract_month - , subq_4.booking__paid_at__extract_day - , subq_4.booking__paid_at__extract_dow - , subq_4.booking__paid_at__extract_doy - , subq_4.metric_time__week - , subq_4.metric_time__quarter - , subq_4.metric_time__year - , subq_4.metric_time__extract_year - , subq_4.metric_time__extract_quarter - , subq_4.metric_time__extract_month - , subq_4.metric_time__extract_day - , subq_4.metric_time__extract_dow - , subq_4.metric_time__extract_doy - , subq_4.listing - , subq_4.guest - , subq_4.host - , subq_4.booking__listing - , subq_4.booking__guest - , subq_4.booking__host - , subq_4.is_instant - , subq_4.booking__is_instant - , subq_4.bookings - , subq_4.instant_bookings - , subq_4.booking_value - , subq_4.max_booking_value - , subq_4.min_booking_value - , subq_4.bookers - , subq_4.average_booking_value - , subq_4.referred_bookings - , subq_4.median_booking_value - , subq_4.booking_value_p99 - , subq_4.discrete_booking_value_p99 - , subq_4.approximate_continuous_booking_value_p99 - , subq_4.approximate_discrete_booking_value_p99 + subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.ds_partitioned__day + , subq_5.ds_partitioned__week + , subq_5.ds_partitioned__month + , subq_5.ds_partitioned__quarter + , subq_5.ds_partitioned__year + , subq_5.ds_partitioned__extract_year + , subq_5.ds_partitioned__extract_quarter + , subq_5.ds_partitioned__extract_month + , subq_5.ds_partitioned__extract_day + , subq_5.ds_partitioned__extract_dow + , subq_5.ds_partitioned__extract_doy + , subq_5.paid_at__day + , subq_5.paid_at__week + , subq_5.paid_at__month + , subq_5.paid_at__quarter + , subq_5.paid_at__year + , subq_5.paid_at__extract_year + , subq_5.paid_at__extract_quarter + , subq_5.paid_at__extract_month + , subq_5.paid_at__extract_day + , subq_5.paid_at__extract_dow + , subq_5.paid_at__extract_doy + , subq_5.booking__ds__day + , subq_5.booking__ds__week + , subq_5.booking__ds__month + , subq_5.booking__ds__quarter + , subq_5.booking__ds__year + , subq_5.booking__ds__extract_year + , subq_5.booking__ds__extract_quarter + , subq_5.booking__ds__extract_month + , subq_5.booking__ds__extract_day + , subq_5.booking__ds__extract_dow + , subq_5.booking__ds__extract_doy + , subq_5.booking__ds_partitioned__day + , subq_5.booking__ds_partitioned__week + , subq_5.booking__ds_partitioned__month + , subq_5.booking__ds_partitioned__quarter + , subq_5.booking__ds_partitioned__year + , subq_5.booking__ds_partitioned__extract_year + , subq_5.booking__ds_partitioned__extract_quarter + , subq_5.booking__ds_partitioned__extract_month + , subq_5.booking__ds_partitioned__extract_day + , subq_5.booking__ds_partitioned__extract_dow + , subq_5.booking__ds_partitioned__extract_doy + , subq_5.booking__paid_at__day + , subq_5.booking__paid_at__week + , subq_5.booking__paid_at__month + , subq_5.booking__paid_at__quarter + , subq_5.booking__paid_at__year + , subq_5.booking__paid_at__extract_year + , subq_5.booking__paid_at__extract_quarter + , subq_5.booking__paid_at__extract_month + , subq_5.booking__paid_at__extract_day + , subq_5.booking__paid_at__extract_dow + , subq_5.booking__paid_at__extract_doy + , subq_5.metric_time__week + , subq_5.metric_time__quarter + , subq_5.metric_time__year + , subq_5.metric_time__extract_year + , subq_5.metric_time__extract_quarter + , subq_5.metric_time__extract_month + , subq_5.metric_time__extract_day + , subq_5.metric_time__extract_dow + , subq_5.metric_time__extract_doy + , subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.listing + , subq_5.guest + , subq_5.host + , subq_5.booking__listing + , subq_5.booking__guest + , subq_5.booking__host + , subq_5.is_instant + , subq_5.booking__is_instant + , subq_5.bookings + , subq_5.instant_bookings + , subq_5.booking_value + , subq_5.max_booking_value + , subq_5.min_booking_value + , subq_5.bookers + , subq_5.average_booking_value + , subq_5.referred_bookings + , subq_5.median_booking_value + , subq_5.booking_value_p99 + , subq_5.discrete_booking_value_p99 + , subq_5.approximate_continuous_booking_value_p99 + , subq_5.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -202,8 +202,8 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -226,12 +226,36 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__month'] SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('month', subq_3.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + , subq_3.metric_time__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,13 +452,13 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - WHERE subq_2.metric_time__month = subq_2.metric_time__day - ) subq_4 + DATE_TRUNC('month', subq_4.metric_time__day) = subq_1.metric_time__day + WHERE subq_4.metric_time__month = subq_4.metric_time__day + ) subq_5 WHERE metric_time__day = '2020-01-01' - ) subq_5 - ) subq_6 + ) subq_6 + ) subq_7 GROUP BY - subq_6.metric_time__month - ) subq_7 -) subq_8 + subq_7.metric_time__month + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 29518080d..bf2aed0b0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -19,10 +19,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_12.ds AS metric_time__day - , DATE_TRUNC('month', subq_12.ds) AS metric_time__month - , subq_10.bookings AS bookings - FROM ***************************.mf_time_spine subq_12 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -30,12 +30,12 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - DATE_TRUNC('month', subq_12.ds) = subq_10.metric_time__day - WHERE DATE_TRUNC('month', subq_12.ds) = subq_12.ds - ) subq_13 + DATE_TRUNC('month', time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', time_spine_src_28006.ds) = time_spine_src_28006.ds + ) subq_15 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month -) subq_17 +) subq_19 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql index e89f0ed24..a9c44081f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.metric_time__month - , subq_7.metric_time__year + subq_8.metric_time__day + , subq_8.metric_time__month + , subq_8.metric_time__year , bookings_start_of_month AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__month - , subq_6.metric_time__year - , subq_6.bookings AS bookings_start_of_month + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , subq_7.bookings AS bookings_start_of_month FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.metric_time__year - , subq_4.bookings + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -108,9 +108,9 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month - , subq_2.metric_time__year AS metric_time__year + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month + , subq_4.metric_time__year AS metric_time__year , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -133,13 +133,39 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('month', subq_3.ds) AS metric_time__month - , DATE_TRUNC('year', subq_3.ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + , subq_3.metric_time__month + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__month + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -336,12 +362,12 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_TRUNC('month', subq_4.metric_time__day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - ) subq_6 -) subq_7 + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index d92697dcf..95d682c27 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql @@ -16,11 +16,11 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ds AS metric_time__day - , DATE_TRUNC('month', subq_11.ds) AS metric_time__month - , DATE_TRUNC('year', subq_11.ds) AS metric_time__year - , SUM(subq_9.bookings) AS bookings_start_of_month - FROM ***************************.mf_time_spine subq_11 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + , SUM(subq_10.bookings) AS bookings_start_of_month + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -28,11 +28,11 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 ON - DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = subq_10.metric_time__day GROUP BY - subq_11.ds - , DATE_TRUNC('month', subq_11.ds) - , DATE_TRUNC('year', subq_11.ds) -) subq_15 + time_spine_src_28006.ds + , DATE_TRUNC('month', time_spine_src_28006.ds) + , DATE_TRUNC('year', time_spine_src_28006.ds) +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql index a9a36007a..7390bca8b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_14.booking__ds__day , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) AS booking__ds__day + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) AS booking__ds__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + , MAX(subq_13.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.booking__ds__day - , subq_11.bookings AS bookings_at_start_of_month + subq_12.booking__ds__day + , subq_12.bookings AS bookings_at_start_of_month FROM ( -- Aggregate Measures SELECT - subq_10.booking__ds__day - , SUM(subq_10.bookings) AS bookings + subq_11.booking__ds__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__ds__day'] SELECT - subq_9.booking__ds__day - , subq_9.bookings + subq_10.booking__ds__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.booking__ds__day AS booking__ds__day + , subq_9.booking__ds__day AS booking__ds__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,33 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['booking__ds__day', 'booking__ds__day'] SELECT - subq_8.ds AS booking__ds__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.booking__ds__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS booking__ds__day + , subq_7.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +567,15 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('month', subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATE_TRUNC('month', subq_9.booking__ds__day) = subq_6.booking__ds__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_11.booking__ds__day + ) subq_12 + ) subq_13 ON - subq_4.booking__ds__day = subq_12.booking__ds__day + subq_4.booking__ds__day = subq_13.booking__ds__day GROUP BY - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index 8fadab17b..c9d0b3138 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.booking__ds__day, subq_28.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY booking__ds__day - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'booking__ds__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS booking__ds__day - , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + time_spine_src_28006.ds AS booking__ds__day + , SUM(subq_21.bookings) AS bookings_at_start_of_month + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_TRUNC('month', subq_22.ds) = subq_20.booking__ds__day + DATE_TRUNC('month', time_spine_src_28006.ds) = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + time_spine_src_28006.ds + ) subq_28 ON - subq_18.booking__ds__day = subq_26.booking__ds__day + subq_19.booking__ds__day = subq_28.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) -) subq_27 + COALESCE(subq_19.booking__ds__day, subq_28.booking__ds__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index 547e6fe97..a456e1772 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_15.metric_time__month + subq_16.metric_time__month , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_8.metric_time__month, subq_14.metric_time__month) AS metric_time__month - , MAX(subq_8.booking_value) AS booking_value - , MAX(subq_14.bookers) AS bookers + COALESCE(subq_9.metric_time__month, subq_15.metric_time__month) AS metric_time__month + , MAX(subq_9.booking_value) AS booking_value + , MAX(subq_15.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__month - , subq_7.booking_value + subq_8.metric_time__month + , subq_8.booking_value FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__month - , SUM(subq_6.booking_value) AS booking_value + subq_7.metric_time__month + , SUM(subq_7.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__month'] SELECT - subq_5.metric_time__month - , subq_5.booking_value + subq_6.metric_time__month + , subq_6.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.ds__day - , subq_4.ds__week - , subq_4.ds__month - , subq_4.ds__quarter - , subq_4.ds__year - , subq_4.ds__extract_year - , subq_4.ds__extract_quarter - , subq_4.ds__extract_month - , subq_4.ds__extract_day - , subq_4.ds__extract_dow - , subq_4.ds__extract_doy - , subq_4.ds_partitioned__day - , subq_4.ds_partitioned__week - , subq_4.ds_partitioned__month - , subq_4.ds_partitioned__quarter - , subq_4.ds_partitioned__year - , subq_4.ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy - , subq_4.paid_at__day - , subq_4.paid_at__week - , subq_4.paid_at__month - , subq_4.paid_at__quarter - , subq_4.paid_at__year - , subq_4.paid_at__extract_year - , subq_4.paid_at__extract_quarter - , subq_4.paid_at__extract_month - , subq_4.paid_at__extract_day - , subq_4.paid_at__extract_dow - , subq_4.paid_at__extract_doy - , subq_4.booking__ds__day - , subq_4.booking__ds__week - , subq_4.booking__ds__month - , subq_4.booking__ds__quarter - , subq_4.booking__ds__year - , subq_4.booking__ds__extract_year - , subq_4.booking__ds__extract_quarter - , subq_4.booking__ds__extract_month - , subq_4.booking__ds__extract_day - , subq_4.booking__ds__extract_dow - , subq_4.booking__ds__extract_doy - , subq_4.booking__ds_partitioned__day - , subq_4.booking__ds_partitioned__week - , subq_4.booking__ds_partitioned__month - , subq_4.booking__ds_partitioned__quarter - , subq_4.booking__ds_partitioned__year - , subq_4.booking__ds_partitioned__extract_year - , subq_4.booking__ds_partitioned__extract_quarter - , subq_4.booking__ds_partitioned__extract_month - , subq_4.booking__ds_partitioned__extract_day - , subq_4.booking__ds_partitioned__extract_dow - , subq_4.booking__ds_partitioned__extract_doy - , subq_4.booking__paid_at__day - , subq_4.booking__paid_at__week - , subq_4.booking__paid_at__month - , subq_4.booking__paid_at__quarter - , subq_4.booking__paid_at__year - , subq_4.booking__paid_at__extract_year - , subq_4.booking__paid_at__extract_quarter - , subq_4.booking__paid_at__extract_month - , subq_4.booking__paid_at__extract_day - , subq_4.booking__paid_at__extract_dow - , subq_4.booking__paid_at__extract_doy - , subq_4.metric_time__week - , subq_4.metric_time__quarter - , subq_4.metric_time__year - , subq_4.metric_time__extract_year - , subq_4.metric_time__extract_quarter - , subq_4.metric_time__extract_month - , subq_4.metric_time__extract_day - , subq_4.metric_time__extract_dow - , subq_4.metric_time__extract_doy - , subq_4.listing - , subq_4.guest - , subq_4.host - , subq_4.booking__listing - , subq_4.booking__guest - , subq_4.booking__host - , subq_4.is_instant - , subq_4.booking__is_instant - , subq_4.bookings - , subq_4.instant_bookings - , subq_4.booking_value - , subq_4.max_booking_value - , subq_4.min_booking_value - , subq_4.bookers - , subq_4.average_booking_value - , subq_4.referred_bookings - , subq_4.median_booking_value - , subq_4.booking_value_p99 - , subq_4.discrete_booking_value_p99 - , subq_4.approximate_continuous_booking_value_p99 - , subq_4.approximate_discrete_booking_value_p99 + subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.ds_partitioned__day + , subq_5.ds_partitioned__week + , subq_5.ds_partitioned__month + , subq_5.ds_partitioned__quarter + , subq_5.ds_partitioned__year + , subq_5.ds_partitioned__extract_year + , subq_5.ds_partitioned__extract_quarter + , subq_5.ds_partitioned__extract_month + , subq_5.ds_partitioned__extract_day + , subq_5.ds_partitioned__extract_dow + , subq_5.ds_partitioned__extract_doy + , subq_5.paid_at__day + , subq_5.paid_at__week + , subq_5.paid_at__month + , subq_5.paid_at__quarter + , subq_5.paid_at__year + , subq_5.paid_at__extract_year + , subq_5.paid_at__extract_quarter + , subq_5.paid_at__extract_month + , subq_5.paid_at__extract_day + , subq_5.paid_at__extract_dow + , subq_5.paid_at__extract_doy + , subq_5.booking__ds__day + , subq_5.booking__ds__week + , subq_5.booking__ds__month + , subq_5.booking__ds__quarter + , subq_5.booking__ds__year + , subq_5.booking__ds__extract_year + , subq_5.booking__ds__extract_quarter + , subq_5.booking__ds__extract_month + , subq_5.booking__ds__extract_day + , subq_5.booking__ds__extract_dow + , subq_5.booking__ds__extract_doy + , subq_5.booking__ds_partitioned__day + , subq_5.booking__ds_partitioned__week + , subq_5.booking__ds_partitioned__month + , subq_5.booking__ds_partitioned__quarter + , subq_5.booking__ds_partitioned__year + , subq_5.booking__ds_partitioned__extract_year + , subq_5.booking__ds_partitioned__extract_quarter + , subq_5.booking__ds_partitioned__extract_month + , subq_5.booking__ds_partitioned__extract_day + , subq_5.booking__ds_partitioned__extract_dow + , subq_5.booking__ds_partitioned__extract_doy + , subq_5.booking__paid_at__day + , subq_5.booking__paid_at__week + , subq_5.booking__paid_at__month + , subq_5.booking__paid_at__quarter + , subq_5.booking__paid_at__year + , subq_5.booking__paid_at__extract_year + , subq_5.booking__paid_at__extract_quarter + , subq_5.booking__paid_at__extract_month + , subq_5.booking__paid_at__extract_day + , subq_5.booking__paid_at__extract_dow + , subq_5.booking__paid_at__extract_doy + , subq_5.metric_time__week + , subq_5.metric_time__quarter + , subq_5.metric_time__year + , subq_5.metric_time__extract_year + , subq_5.metric_time__extract_quarter + , subq_5.metric_time__extract_month + , subq_5.metric_time__extract_day + , subq_5.metric_time__extract_dow + , subq_5.metric_time__extract_doy + , subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.listing + , subq_5.guest + , subq_5.host + , subq_5.booking__listing + , subq_5.booking__guest + , subq_5.booking__host + , subq_5.is_instant + , subq_5.booking__is_instant + , subq_5.bookings + , subq_5.instant_bookings + , subq_5.booking_value + , subq_5.max_booking_value + , subq_5.min_booking_value + , subq_5.bookers + , subq_5.average_booking_value + , subq_5.referred_bookings + , subq_5.median_booking_value + , subq_5.booking_value_p99 + , subq_5.discrete_booking_value_p99 + , subq_5.approximate_continuous_booking_value_p99 + , subq_5.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -208,8 +208,8 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -232,12 +232,36 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__month'] SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('month', subq_3.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + , subq_3.metric_time__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__day + , subq_2.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -434,232 +458,232 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day - ) subq_4 + subq_4.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day + ) subq_5 WHERE metric_time__day = '2020-01-01' - ) subq_5 - ) subq_6 + ) subq_6 + ) subq_7 GROUP BY - subq_6.metric_time__month - ) subq_7 - ) subq_8 + subq_7.metric_time__month + ) subq_8 + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_13.metric_time__month - , subq_13.bookers + subq_14.metric_time__month + , subq_14.bookers FROM ( -- Aggregate Measures SELECT - subq_12.metric_time__month - , COUNT(DISTINCT subq_12.bookers) AS bookers + subq_13.metric_time__month + , COUNT(DISTINCT subq_13.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__month'] SELECT - subq_11.metric_time__month - , subq_11.bookers + subq_12.metric_time__month + , subq_12.bookers FROM ( -- Constrain Output with WHERE SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.ds_partitioned__day - , subq_10.ds_partitioned__week - , subq_10.ds_partitioned__month - , subq_10.ds_partitioned__quarter - , subq_10.ds_partitioned__year - , subq_10.ds_partitioned__extract_year - , subq_10.ds_partitioned__extract_quarter - , subq_10.ds_partitioned__extract_month - , subq_10.ds_partitioned__extract_day - , subq_10.ds_partitioned__extract_dow - , subq_10.ds_partitioned__extract_doy - , subq_10.paid_at__day - , subq_10.paid_at__week - , subq_10.paid_at__month - , subq_10.paid_at__quarter - , subq_10.paid_at__year - , subq_10.paid_at__extract_year - , subq_10.paid_at__extract_quarter - , subq_10.paid_at__extract_month - , subq_10.paid_at__extract_day - , subq_10.paid_at__extract_dow - , subq_10.paid_at__extract_doy - , subq_10.booking__ds__day - , subq_10.booking__ds__week - , subq_10.booking__ds__month - , subq_10.booking__ds__quarter - , subq_10.booking__ds__year - , subq_10.booking__ds__extract_year - , subq_10.booking__ds__extract_quarter - , subq_10.booking__ds__extract_month - , subq_10.booking__ds__extract_day - , subq_10.booking__ds__extract_dow - , subq_10.booking__ds__extract_doy - , subq_10.booking__ds_partitioned__day - , subq_10.booking__ds_partitioned__week - , subq_10.booking__ds_partitioned__month - , subq_10.booking__ds_partitioned__quarter - , subq_10.booking__ds_partitioned__year - , subq_10.booking__ds_partitioned__extract_year - , subq_10.booking__ds_partitioned__extract_quarter - , subq_10.booking__ds_partitioned__extract_month - , subq_10.booking__ds_partitioned__extract_day - , subq_10.booking__ds_partitioned__extract_dow - , subq_10.booking__ds_partitioned__extract_doy - , subq_10.booking__paid_at__day - , subq_10.booking__paid_at__week - , subq_10.booking__paid_at__month - , subq_10.booking__paid_at__quarter - , subq_10.booking__paid_at__year - , subq_10.booking__paid_at__extract_year - , subq_10.booking__paid_at__extract_quarter - , subq_10.booking__paid_at__extract_month - , subq_10.booking__paid_at__extract_day - , subq_10.booking__paid_at__extract_dow - , subq_10.booking__paid_at__extract_doy - , subq_10.metric_time__day - , subq_10.metric_time__week - , subq_10.metric_time__month - , subq_10.metric_time__quarter - , subq_10.metric_time__year - , subq_10.metric_time__extract_year - , subq_10.metric_time__extract_quarter - , subq_10.metric_time__extract_month - , subq_10.metric_time__extract_day - , subq_10.metric_time__extract_dow - , subq_10.metric_time__extract_doy - , subq_10.listing - , subq_10.guest - , subq_10.host - , subq_10.booking__listing - , subq_10.booking__guest - , subq_10.booking__host - , subq_10.is_instant - , subq_10.booking__is_instant - , subq_10.bookings - , subq_10.instant_bookings - , subq_10.booking_value - , subq_10.max_booking_value - , subq_10.min_booking_value - , subq_10.bookers - , subq_10.average_booking_value - , subq_10.referred_bookings - , subq_10.median_booking_value - , subq_10.booking_value_p99 - , subq_10.discrete_booking_value_p99 - , subq_10.approximate_continuous_booking_value_p99 - , subq_10.approximate_discrete_booking_value_p99 + subq_11.ds__day + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , subq_11.ds__year + , subq_11.ds__extract_year + , subq_11.ds__extract_quarter + , subq_11.ds__extract_month + , subq_11.ds__extract_day + , subq_11.ds__extract_dow + , subq_11.ds__extract_doy + , subq_11.ds_partitioned__day + , subq_11.ds_partitioned__week + , subq_11.ds_partitioned__month + , subq_11.ds_partitioned__quarter + , subq_11.ds_partitioned__year + , subq_11.ds_partitioned__extract_year + , subq_11.ds_partitioned__extract_quarter + , subq_11.ds_partitioned__extract_month + , subq_11.ds_partitioned__extract_day + , subq_11.ds_partitioned__extract_dow + , subq_11.ds_partitioned__extract_doy + , subq_11.paid_at__day + , subq_11.paid_at__week + , subq_11.paid_at__month + , subq_11.paid_at__quarter + , subq_11.paid_at__year + , subq_11.paid_at__extract_year + , subq_11.paid_at__extract_quarter + , subq_11.paid_at__extract_month + , subq_11.paid_at__extract_day + , subq_11.paid_at__extract_dow + , subq_11.paid_at__extract_doy + , subq_11.booking__ds__day + , subq_11.booking__ds__week + , subq_11.booking__ds__month + , subq_11.booking__ds__quarter + , subq_11.booking__ds__year + , subq_11.booking__ds__extract_year + , subq_11.booking__ds__extract_quarter + , subq_11.booking__ds__extract_month + , subq_11.booking__ds__extract_day + , subq_11.booking__ds__extract_dow + , subq_11.booking__ds__extract_doy + , subq_11.booking__ds_partitioned__day + , subq_11.booking__ds_partitioned__week + , subq_11.booking__ds_partitioned__month + , subq_11.booking__ds_partitioned__quarter + , subq_11.booking__ds_partitioned__year + , subq_11.booking__ds_partitioned__extract_year + , subq_11.booking__ds_partitioned__extract_quarter + , subq_11.booking__ds_partitioned__extract_month + , subq_11.booking__ds_partitioned__extract_day + , subq_11.booking__ds_partitioned__extract_dow + , subq_11.booking__ds_partitioned__extract_doy + , subq_11.booking__paid_at__day + , subq_11.booking__paid_at__week + , subq_11.booking__paid_at__month + , subq_11.booking__paid_at__quarter + , subq_11.booking__paid_at__year + , subq_11.booking__paid_at__extract_year + , subq_11.booking__paid_at__extract_quarter + , subq_11.booking__paid_at__extract_month + , subq_11.booking__paid_at__extract_day + , subq_11.booking__paid_at__extract_dow + , subq_11.booking__paid_at__extract_doy + , subq_11.metric_time__day + , subq_11.metric_time__week + , subq_11.metric_time__month + , subq_11.metric_time__quarter + , subq_11.metric_time__year + , subq_11.metric_time__extract_year + , subq_11.metric_time__extract_quarter + , subq_11.metric_time__extract_month + , subq_11.metric_time__extract_day + , subq_11.metric_time__extract_dow + , subq_11.metric_time__extract_doy + , subq_11.listing + , subq_11.guest + , subq_11.host + , subq_11.booking__listing + , subq_11.booking__guest + , subq_11.booking__host + , subq_11.is_instant + , subq_11.booking__is_instant + , subq_11.bookings + , subq_11.instant_bookings + , subq_11.booking_value + , subq_11.max_booking_value + , subq_11.min_booking_value + , subq_11.bookers + , subq_11.average_booking_value + , subq_11.referred_bookings + , subq_11.median_booking_value + , subq_11.booking_value_p99 + , subq_11.discrete_booking_value_p99 + , subq_11.approximate_continuous_booking_value_p99 + , subq_11.approximate_discrete_booking_value_p99 FROM ( -- Metric Time Dimension 'ds' SELECT - subq_9.ds__day - , subq_9.ds__week - , subq_9.ds__month - , subq_9.ds__quarter - , subq_9.ds__year - , subq_9.ds__extract_year - , subq_9.ds__extract_quarter - , subq_9.ds__extract_month - , subq_9.ds__extract_day - , subq_9.ds__extract_dow - , subq_9.ds__extract_doy - , subq_9.ds_partitioned__day - , subq_9.ds_partitioned__week - , subq_9.ds_partitioned__month - , subq_9.ds_partitioned__quarter - , subq_9.ds_partitioned__year - , subq_9.ds_partitioned__extract_year - , subq_9.ds_partitioned__extract_quarter - , subq_9.ds_partitioned__extract_month - , subq_9.ds_partitioned__extract_day - , subq_9.ds_partitioned__extract_dow - , subq_9.ds_partitioned__extract_doy - , subq_9.paid_at__day - , subq_9.paid_at__week - , subq_9.paid_at__month - , subq_9.paid_at__quarter - , subq_9.paid_at__year - , subq_9.paid_at__extract_year - , subq_9.paid_at__extract_quarter - , subq_9.paid_at__extract_month - , subq_9.paid_at__extract_day - , subq_9.paid_at__extract_dow - , subq_9.paid_at__extract_doy - , subq_9.booking__ds__day - , subq_9.booking__ds__week - , subq_9.booking__ds__month - , subq_9.booking__ds__quarter - , subq_9.booking__ds__year - , subq_9.booking__ds__extract_year - , subq_9.booking__ds__extract_quarter - , subq_9.booking__ds__extract_month - , subq_9.booking__ds__extract_day - , subq_9.booking__ds__extract_dow - , subq_9.booking__ds__extract_doy - , subq_9.booking__ds_partitioned__day - , subq_9.booking__ds_partitioned__week - , subq_9.booking__ds_partitioned__month - , subq_9.booking__ds_partitioned__quarter - , subq_9.booking__ds_partitioned__year - , subq_9.booking__ds_partitioned__extract_year - , subq_9.booking__ds_partitioned__extract_quarter - , subq_9.booking__ds_partitioned__extract_month - , subq_9.booking__ds_partitioned__extract_day - , subq_9.booking__ds_partitioned__extract_dow - , subq_9.booking__ds_partitioned__extract_doy - , subq_9.booking__paid_at__day - , subq_9.booking__paid_at__week - , subq_9.booking__paid_at__month - , subq_9.booking__paid_at__quarter - , subq_9.booking__paid_at__year - , subq_9.booking__paid_at__extract_year - , subq_9.booking__paid_at__extract_quarter - , subq_9.booking__paid_at__extract_month - , subq_9.booking__paid_at__extract_day - , subq_9.booking__paid_at__extract_dow - , subq_9.booking__paid_at__extract_doy - , subq_9.ds__day AS metric_time__day - , subq_9.ds__week AS metric_time__week - , subq_9.ds__month AS metric_time__month - , subq_9.ds__quarter AS metric_time__quarter - , subq_9.ds__year AS metric_time__year - , subq_9.ds__extract_year AS metric_time__extract_year - , subq_9.ds__extract_quarter AS metric_time__extract_quarter - , subq_9.ds__extract_month AS metric_time__extract_month - , subq_9.ds__extract_day AS metric_time__extract_day - , subq_9.ds__extract_dow AS metric_time__extract_dow - , subq_9.ds__extract_doy AS metric_time__extract_doy - , subq_9.listing - , subq_9.guest - , subq_9.host - , subq_9.booking__listing - , subq_9.booking__guest - , subq_9.booking__host - , subq_9.is_instant - , subq_9.booking__is_instant - , subq_9.bookings - , subq_9.instant_bookings - , subq_9.booking_value - , subq_9.max_booking_value - , subq_9.min_booking_value - , subq_9.bookers - , subq_9.average_booking_value - , subq_9.referred_bookings - , subq_9.median_booking_value - , subq_9.booking_value_p99 - , subq_9.discrete_booking_value_p99 - , subq_9.approximate_continuous_booking_value_p99 - , subq_9.approximate_discrete_booking_value_p99 + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -752,17 +776,17 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 - ) subq_10 + ) subq_10 + ) subq_11 WHERE metric_time__day = '2020-01-01' - ) subq_11 - ) subq_12 + ) subq_12 + ) subq_13 GROUP BY - subq_12.metric_time__month - ) subq_13 - ) subq_14 + subq_13.metric_time__month + ) subq_14 + ) subq_15 ON - subq_8.metric_time__month = subq_14.metric_time__month + subq_9.metric_time__month = subq_15.metric_time__month GROUP BY - COALESCE(subq_8.metric_time__month, subq_14.metric_time__month) -) subq_15 + COALESCE(subq_9.metric_time__month, subq_15.metric_time__month) +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 63f543a97..408e5a621 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -11,9 +11,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__month, subq_30.metric_time__month) AS metric_time__month - , MAX(subq_24.booking_value) AS booking_value - , MAX(subq_30.bookers) AS bookers + COALESCE(subq_26.metric_time__month, subq_32.metric_time__month) AS metric_time__month + , MAX(subq_26.booking_value) AS booking_value + , MAX(subq_32.bookers) AS bookers FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__month'] @@ -25,19 +25,19 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_19.ds AS metric_time__day - , DATE_TRUNC('month', subq_19.ds) AS metric_time__month + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month , bookings_source_src_28000.booking_value AS booking_value - FROM ***************************.mf_time_spine subq_19 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_19.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + time_spine_src_28006.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + ) subq_22 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_24 + ) subq_26 FULL OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookers', 'metric_time__month'] @@ -54,13 +54,13 @@ FROM ( , DATE_TRUNC('month', ds) AS metric_time__month , guest_id AS bookers FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_28 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_30 + ) subq_32 ON - subq_24.metric_time__month = subq_30.metric_time__month + subq_26.metric_time__month = subq_32.metric_time__month GROUP BY - COALESCE(subq_24.metric_time__month, subq_30.metric_time__month) -) subq_31 + COALESCE(subq_26.metric_time__month, subq_32.metric_time__month) +) subq_33 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql index 3b4a0a588..1d6312654 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day - , subq_13.metric_time__month - , subq_13.metric_time__year + subq_14.metric_time__day + , subq_14.metric_time__month + , subq_14.metric_time__year , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day - , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) AS metric_time__month - , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) AS metric_time__year - , MAX(subq_7.booking_value) AS booking_value - , MAX(subq_12.bookers) AS bookers + COALESCE(subq_8.metric_time__day, subq_13.metric_time__day) AS metric_time__day + , COALESCE(subq_8.metric_time__month, subq_13.metric_time__month) AS metric_time__month + , COALESCE(subq_8.metric_time__year, subq_13.metric_time__year) AS metric_time__year + , MAX(subq_8.booking_value) AS booking_value + , MAX(subq_13.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__month - , subq_6.metric_time__year - , subq_6.booking_value + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , subq_7.booking_value FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - , SUM(subq_5.booking_value) AS booking_value + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , SUM(subq_6.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.metric_time__year - , subq_4.booking_value + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , subq_5.booking_value FROM ( -- Join to Time Spine Dataset SELECT @@ -116,9 +116,9 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month - , subq_2.metric_time__year AS metric_time__year + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month + , subq_4.metric_time__year AS metric_time__year , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -141,13 +141,39 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('month', subq_3.ds) AS metric_time__month - , DATE_TRUNC('year', subq_3.ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + , subq_3.metric_time__month + , subq_3.metric_time__year + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__year AS metric_time__year + , subq_2.ds__day + , subq_2.ds__month + , subq_2.ds__year + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -344,137 +370,137 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - ) subq_6 - ) subq_7 + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.metric_time__month - , subq_11.metric_time__year - , subq_11.bookers + subq_12.metric_time__day + , subq_12.metric_time__month + , subq_12.metric_time__year + , subq_12.bookers FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__day - , subq_10.metric_time__month - , subq_10.metric_time__year - , COUNT(DISTINCT subq_10.bookers) AS bookers + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + , COUNT(DISTINCT subq_11.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_9.metric_time__day - , subq_9.metric_time__month - , subq_9.metric_time__year - , subq_9.bookers + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + , subq_10.bookers FROM ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -567,25 +593,25 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 - ) subq_10 + ) subq_9 + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__day - , subq_10.metric_time__month - , subq_10.metric_time__year - ) subq_11 - ) subq_12 + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + ) subq_12 + ) subq_13 ON ( - subq_7.metric_time__day = subq_12.metric_time__day + subq_8.metric_time__day = subq_13.metric_time__day ) AND ( - subq_7.metric_time__month = subq_12.metric_time__month + subq_8.metric_time__month = subq_13.metric_time__month ) AND ( - subq_7.metric_time__year = subq_12.metric_time__year + subq_8.metric_time__year = subq_13.metric_time__year ) GROUP BY - COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) - , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) - , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) -) subq_13 + COALESCE(subq_8.metric_time__day, subq_13.metric_time__day) + , COALESCE(subq_8.metric_time__month, subq_13.metric_time__month) + , COALESCE(subq_8.metric_time__year, subq_13.metric_time__year) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 0c93f0425..917fe0c41 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql @@ -13,31 +13,31 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) AS metric_time__day - , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) AS metric_time__month - , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) AS metric_time__year - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_26.bookers) AS bookers + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , COALESCE(subq_23.metric_time__month, subq_28.metric_time__month) AS metric_time__month + , COALESCE(subq_23.metric_time__year, subq_28.metric_time__year) AS metric_time__year + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_28.bookers) AS bookers FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS metric_time__day - , DATE_TRUNC('month', subq_17.ds) AS metric_time__month - , DATE_TRUNC('year', subq_17.ds) AS metric_time__year + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(bookings_source_src_28000.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_17.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + time_spine_src_28006.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - , DATE_TRUNC('month', subq_17.ds) - , DATE_TRUNC('year', subq_17.ds) - ) subq_21 + time_spine_src_28006.ds + , DATE_TRUNC('month', time_spine_src_28006.ds) + , DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -54,17 +54,17 @@ FROM ( DATE_TRUNC('day', ds) , DATE_TRUNC('month', ds) , DATE_TRUNC('year', ds) - ) subq_26 + ) subq_28 ON ( - subq_21.metric_time__day = subq_26.metric_time__day + subq_23.metric_time__day = subq_28.metric_time__day ) AND ( - subq_21.metric_time__month = subq_26.metric_time__month + subq_23.metric_time__month = subq_28.metric_time__month ) AND ( - subq_21.metric_time__year = subq_26.metric_time__year + subq_23.metric_time__year = subq_28.metric_time__year ) GROUP BY - COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) - , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) - , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) -) subq_27 + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) + , COALESCE(subq_23.metric_time__month, subq_28.metric_time__month) + , COALESCE(subq_23.metric_time__year, subq_28.metric_time__year) +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql index 6c2e29f3a..8b6e243b5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_14.booking__ds__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) AS booking__ds__day + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) AS booking__ds__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.booking__ds__day - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.booking__ds__day + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.booking__ds__day - , SUM(subq_10.bookings) AS bookings + subq_11.booking__ds__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__ds__day'] SELECT - subq_9.booking__ds__day - , subq_9.bookings + subq_10.booking__ds__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.booking__ds__day AS booking__ds__day + , subq_9.booking__ds__day AS booking__ds__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,33 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['booking__ds__day', 'booking__ds__day'] SELECT - subq_8.ds AS booking__ds__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.booking__ds__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS booking__ds__day + , subq_7.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +567,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.booking__ds__day - INTERVAL 14 day = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + subq_9.booking__ds__day - INTERVAL 14 day = subq_6.booking__ds__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_11.booking__ds__day + ) subq_12 + ) subq_13 ON - subq_4.booking__ds__day = subq_12.booking__ds__day + subq_4.booking__ds__day = subq_13.booking__ds__day GROUP BY - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql index 84c0c9aea..cc540d2ea 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.booking__ds__day, subq_28.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY booking__ds__day - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'booking__ds__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS booking__ds__day - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + time_spine_src_28006.ds AS booking__ds__day + , SUM(subq_21.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - subq_22.ds - INTERVAL 14 day = subq_20.booking__ds__day + time_spine_src_28006.ds - INTERVAL 14 day = subq_21.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + time_spine_src_28006.ds + ) subq_28 ON - subq_18.booking__ds__day = subq_26.booking__ds__day + subq_19.booking__ds__day = subq_28.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) -) subq_27 + COALESCE(subq_19.booking__ds__day, subq_28.booking__ds__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql index 8ab0d9ab9..ffc964561 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day + subq_9.metric_time__day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.bookings AS bookings_5_days_ago + subq_8.metric_time__day + , subq_8.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__day - , SUM(subq_6.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_5.metric_time__day - , subq_5.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Time Range to [2019-12-19T00:00:00, 2020-01-02T00:00:00] SELECT - subq_4.metric_time__day - , subq_4.ds__day - , subq_4.ds__week - , subq_4.ds__month - , subq_4.ds__quarter - , subq_4.ds__year - , subq_4.ds__extract_year - , subq_4.ds__extract_quarter - , subq_4.ds__extract_month - , subq_4.ds__extract_day - , subq_4.ds__extract_dow - , subq_4.ds__extract_doy - , subq_4.ds_partitioned__day - , subq_4.ds_partitioned__week - , subq_4.ds_partitioned__month - , subq_4.ds_partitioned__quarter - , subq_4.ds_partitioned__year - , subq_4.ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy - , subq_4.paid_at__day - , subq_4.paid_at__week - , subq_4.paid_at__month - , subq_4.paid_at__quarter - , subq_4.paid_at__year - , subq_4.paid_at__extract_year - , subq_4.paid_at__extract_quarter - , subq_4.paid_at__extract_month - , subq_4.paid_at__extract_day - , subq_4.paid_at__extract_dow - , subq_4.paid_at__extract_doy - , subq_4.booking__ds__day - , subq_4.booking__ds__week - , subq_4.booking__ds__month - , subq_4.booking__ds__quarter - , subq_4.booking__ds__year - , subq_4.booking__ds__extract_year - , subq_4.booking__ds__extract_quarter - , subq_4.booking__ds__extract_month - , subq_4.booking__ds__extract_day - , subq_4.booking__ds__extract_dow - , subq_4.booking__ds__extract_doy - , subq_4.booking__ds_partitioned__day - , subq_4.booking__ds_partitioned__week - , subq_4.booking__ds_partitioned__month - , subq_4.booking__ds_partitioned__quarter - , subq_4.booking__ds_partitioned__year - , subq_4.booking__ds_partitioned__extract_year - , subq_4.booking__ds_partitioned__extract_quarter - , subq_4.booking__ds_partitioned__extract_month - , subq_4.booking__ds_partitioned__extract_day - , subq_4.booking__ds_partitioned__extract_dow - , subq_4.booking__ds_partitioned__extract_doy - , subq_4.booking__paid_at__day - , subq_4.booking__paid_at__week - , subq_4.booking__paid_at__month - , subq_4.booking__paid_at__quarter - , subq_4.booking__paid_at__year - , subq_4.booking__paid_at__extract_year - , subq_4.booking__paid_at__extract_quarter - , subq_4.booking__paid_at__extract_month - , subq_4.booking__paid_at__extract_day - , subq_4.booking__paid_at__extract_dow - , subq_4.booking__paid_at__extract_doy - , subq_4.metric_time__week - , subq_4.metric_time__month - , subq_4.metric_time__quarter - , subq_4.metric_time__year - , subq_4.metric_time__extract_year - , subq_4.metric_time__extract_quarter - , subq_4.metric_time__extract_month - , subq_4.metric_time__extract_day - , subq_4.metric_time__extract_dow - , subq_4.metric_time__extract_doy - , subq_4.listing - , subq_4.guest - , subq_4.host - , subq_4.booking__listing - , subq_4.booking__guest - , subq_4.booking__host - , subq_4.is_instant - , subq_4.booking__is_instant - , subq_4.bookings - , subq_4.instant_bookings - , subq_4.booking_value - , subq_4.max_booking_value - , subq_4.min_booking_value - , subq_4.bookers - , subq_4.average_booking_value - , subq_4.referred_bookings - , subq_4.median_booking_value - , subq_4.booking_value_p99 - , subq_4.discrete_booking_value_p99 - , subq_4.approximate_continuous_booking_value_p99 - , subq_4.approximate_discrete_booking_value_p99 + subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.ds_partitioned__day + , subq_5.ds_partitioned__week + , subq_5.ds_partitioned__month + , subq_5.ds_partitioned__quarter + , subq_5.ds_partitioned__year + , subq_5.ds_partitioned__extract_year + , subq_5.ds_partitioned__extract_quarter + , subq_5.ds_partitioned__extract_month + , subq_5.ds_partitioned__extract_day + , subq_5.ds_partitioned__extract_dow + , subq_5.ds_partitioned__extract_doy + , subq_5.paid_at__day + , subq_5.paid_at__week + , subq_5.paid_at__month + , subq_5.paid_at__quarter + , subq_5.paid_at__year + , subq_5.paid_at__extract_year + , subq_5.paid_at__extract_quarter + , subq_5.paid_at__extract_month + , subq_5.paid_at__extract_day + , subq_5.paid_at__extract_dow + , subq_5.paid_at__extract_doy + , subq_5.booking__ds__day + , subq_5.booking__ds__week + , subq_5.booking__ds__month + , subq_5.booking__ds__quarter + , subq_5.booking__ds__year + , subq_5.booking__ds__extract_year + , subq_5.booking__ds__extract_quarter + , subq_5.booking__ds__extract_month + , subq_5.booking__ds__extract_day + , subq_5.booking__ds__extract_dow + , subq_5.booking__ds__extract_doy + , subq_5.booking__ds_partitioned__day + , subq_5.booking__ds_partitioned__week + , subq_5.booking__ds_partitioned__month + , subq_5.booking__ds_partitioned__quarter + , subq_5.booking__ds_partitioned__year + , subq_5.booking__ds_partitioned__extract_year + , subq_5.booking__ds_partitioned__extract_quarter + , subq_5.booking__ds_partitioned__extract_month + , subq_5.booking__ds_partitioned__extract_day + , subq_5.booking__ds_partitioned__extract_dow + , subq_5.booking__ds_partitioned__extract_doy + , subq_5.booking__paid_at__day + , subq_5.booking__paid_at__week + , subq_5.booking__paid_at__month + , subq_5.booking__paid_at__quarter + , subq_5.booking__paid_at__year + , subq_5.booking__paid_at__extract_year + , subq_5.booking__paid_at__extract_quarter + , subq_5.booking__paid_at__extract_month + , subq_5.booking__paid_at__extract_day + , subq_5.booking__paid_at__extract_dow + , subq_5.booking__paid_at__extract_doy + , subq_5.metric_time__week + , subq_5.metric_time__month + , subq_5.metric_time__quarter + , subq_5.metric_time__year + , subq_5.metric_time__extract_year + , subq_5.metric_time__extract_quarter + , subq_5.metric_time__extract_month + , subq_5.metric_time__extract_day + , subq_5.metric_time__extract_dow + , subq_5.metric_time__extract_doy + , subq_5.metric_time__day + , subq_5.listing + , subq_5.guest + , subq_5.host + , subq_5.booking__listing + , subq_5.booking__guest + , subq_5.booking__host + , subq_5.is_instant + , subq_5.booking__is_instant + , subq_5.bookings + , subq_5.instant_bookings + , subq_5.booking_value + , subq_5.max_booking_value + , subq_5.min_booking_value + , subq_5.bookers + , subq_5.average_booking_value + , subq_5.referred_bookings + , subq_5.median_booking_value + , subq_5.booking_value_p99 + , subq_5.discrete_booking_value_p99 + , subq_5.approximate_continuous_booking_value_p99 + , subq_5.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -201,7 +201,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -224,11 +224,33 @@ FROM ( , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 + subq_3.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -425,12 +447,12 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - WHERE subq_4.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' - ) subq_5 - ) subq_6 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + WHERE subq_5.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' + ) subq_6 + ) subq_7 GROUP BY - subq_6.metric_time__day - ) subq_7 -) subq_8 + subq_7.metric_time__day + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index 9e6a52124..749d48dc3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql @@ -13,9 +13,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.ds AS metric_time__day - , SUM(subq_10.bookings) AS bookings_5_days_ago - FROM ***************************.mf_time_spine subq_12 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_11.bookings) AS bookings_5_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -23,10 +23,10 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - subq_12.ds - INTERVAL 5 day = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + time_spine_src_28006.ds - INTERVAL 5 day = subq_11.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_12.ds -) subq_17 + time_spine_src_28006.ds +) subq_19 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0.sql index bde8e6592..0404b1219 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day - , COALESCE(subq_9.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 + subq_10.metric_time__day + , COALESCE(subq_10.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_7.metric_time__day AS metric_time__day + subq_9.metric_time__day AS metric_time__day , subq_6.bookers AS bookers FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +363,5 @@ FROM ( subq_5.metric_time__day ) subq_6 ON - subq_7.metric_time__day = subq_6.metric_time__day -) subq_9 + subq_9.metric_time__day = subq_6.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql index 1f7ba0288..15065b1c7 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql @@ -9,28 +9,28 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_18.ds AS metric_time__day - , subq_16.bookers AS bookers - FROM ***************************.mf_time_spine subq_18 + time_spine_src_28006.ds AS metric_time__day + , subq_17.bookers AS bookers + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__day'] -- Aggregate Measures SELECT - subq_13.ds AS metric_time__day + subq_14.ds AS metric_time__day , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ***************************.mf_time_spine subq_13 + FROM ***************************.mf_time_spine subq_14 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_13.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_13.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.ds - INTERVAL 2 day ) GROUP BY - subq_13.ds - ) subq_16 + subq_14.ds + ) subq_17 ON - subq_18.ds = subq_16.metric_time__day -) subq_19 + time_spine_src_28006.ds = subq_17.metric_time__day +) subq_21 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql index b9c24f20a..9c6d01cbf 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_16.metric_time__day + subq_18.metric_time__day , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_7.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , MAX(subq_15.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_8.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , MAX(subq_17.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 + subq_7.metric_time__day + , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ds__day AS metric_time__day + , subq_4.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -238,232 +260,254 @@ FROM ( subq_2.metric_time__day ) subq_3 ON - subq_4.metric_time__day = subq_3.metric_time__day - ) subq_6 - ) subq_7 + subq_6.metric_time__day = subq_3.metric_time__day + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day - , subq_14.bookings AS bookings_2_weeks_ago + subq_16.metric_time__day + , subq_16.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_13.metric_time__day - , SUM(subq_13.bookings) AS bookings + subq_15.metric_time__day + , SUM(subq_15.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_12.metric_time__day - , subq_12.bookings + subq_14.metric_time__day + , subq_14.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_9.ds__day AS ds__day - , subq_9.ds__week AS ds__week - , subq_9.ds__month AS ds__month - , subq_9.ds__quarter AS ds__quarter - , subq_9.ds__year AS ds__year - , subq_9.ds__extract_year AS ds__extract_year - , subq_9.ds__extract_quarter AS ds__extract_quarter - , subq_9.ds__extract_month AS ds__extract_month - , subq_9.ds__extract_day AS ds__extract_day - , subq_9.ds__extract_dow AS ds__extract_dow - , subq_9.ds__extract_doy AS ds__extract_doy - , subq_9.ds_partitioned__day AS ds_partitioned__day - , subq_9.ds_partitioned__week AS ds_partitioned__week - , subq_9.ds_partitioned__month AS ds_partitioned__month - , subq_9.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_9.ds_partitioned__year AS ds_partitioned__year - , subq_9.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_9.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_9.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_9.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_9.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_9.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_9.paid_at__day AS paid_at__day - , subq_9.paid_at__week AS paid_at__week - , subq_9.paid_at__month AS paid_at__month - , subq_9.paid_at__quarter AS paid_at__quarter - , subq_9.paid_at__year AS paid_at__year - , subq_9.paid_at__extract_year AS paid_at__extract_year - , subq_9.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_9.paid_at__extract_month AS paid_at__extract_month - , subq_9.paid_at__extract_day AS paid_at__extract_day - , subq_9.paid_at__extract_dow AS paid_at__extract_dow - , subq_9.paid_at__extract_doy AS paid_at__extract_doy - , subq_9.booking__ds__day AS booking__ds__day - , subq_9.booking__ds__week AS booking__ds__week - , subq_9.booking__ds__month AS booking__ds__month - , subq_9.booking__ds__quarter AS booking__ds__quarter - , subq_9.booking__ds__year AS booking__ds__year - , subq_9.booking__ds__extract_year AS booking__ds__extract_year - , subq_9.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_9.booking__ds__extract_month AS booking__ds__extract_month - , subq_9.booking__ds__extract_day AS booking__ds__extract_day - , subq_9.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_9.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_9.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_9.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_9.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_9.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_9.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_9.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_9.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_9.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_9.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_9.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_9.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_9.booking__paid_at__day AS booking__paid_at__day - , subq_9.booking__paid_at__week AS booking__paid_at__week - , subq_9.booking__paid_at__month AS booking__paid_at__month - , subq_9.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_9.booking__paid_at__year AS booking__paid_at__year - , subq_9.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_9.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_9.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_9.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_9.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_9.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_9.metric_time__week AS metric_time__week - , subq_9.metric_time__month AS metric_time__month - , subq_9.metric_time__quarter AS metric_time__quarter - , subq_9.metric_time__year AS metric_time__year - , subq_9.metric_time__extract_year AS metric_time__extract_year - , subq_9.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_9.metric_time__extract_month AS metric_time__extract_month - , subq_9.metric_time__extract_day AS metric_time__extract_day - , subq_9.metric_time__extract_dow AS metric_time__extract_dow - , subq_9.metric_time__extract_doy AS metric_time__extract_doy - , subq_10.metric_time__day AS metric_time__day - , subq_9.listing AS listing - , subq_9.guest AS guest - , subq_9.host AS host - , subq_9.booking__listing AS booking__listing - , subq_9.booking__guest AS booking__guest - , subq_9.booking__host AS booking__host - , subq_9.is_instant AS is_instant - , subq_9.booking__is_instant AS booking__is_instant - , subq_9.bookings AS bookings - , subq_9.instant_bookings AS instant_bookings - , subq_9.booking_value AS booking_value - , subq_9.max_booking_value AS max_booking_value - , subq_9.min_booking_value AS min_booking_value - , subq_9.bookers AS bookers - , subq_9.average_booking_value AS average_booking_value - , subq_9.referred_bookings AS referred_bookings - , subq_9.median_booking_value AS median_booking_value - , subq_9.booking_value_p99 AS booking_value_p99 - , subq_9.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_9.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_9.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_10.ds__day AS ds__day + , subq_10.ds__week AS ds__week + , subq_10.ds__month AS ds__month + , subq_10.ds__quarter AS ds__quarter + , subq_10.ds__year AS ds__year + , subq_10.ds__extract_year AS ds__extract_year + , subq_10.ds__extract_quarter AS ds__extract_quarter + , subq_10.ds__extract_month AS ds__extract_month + , subq_10.ds__extract_day AS ds__extract_day + , subq_10.ds__extract_dow AS ds__extract_dow + , subq_10.ds__extract_doy AS ds__extract_doy + , subq_10.ds_partitioned__day AS ds_partitioned__day + , subq_10.ds_partitioned__week AS ds_partitioned__week + , subq_10.ds_partitioned__month AS ds_partitioned__month + , subq_10.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_10.ds_partitioned__year AS ds_partitioned__year + , subq_10.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_10.paid_at__day AS paid_at__day + , subq_10.paid_at__week AS paid_at__week + , subq_10.paid_at__month AS paid_at__month + , subq_10.paid_at__quarter AS paid_at__quarter + , subq_10.paid_at__year AS paid_at__year + , subq_10.paid_at__extract_year AS paid_at__extract_year + , subq_10.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_10.paid_at__extract_month AS paid_at__extract_month + , subq_10.paid_at__extract_day AS paid_at__extract_day + , subq_10.paid_at__extract_dow AS paid_at__extract_dow + , subq_10.paid_at__extract_doy AS paid_at__extract_doy + , subq_10.booking__ds__day AS booking__ds__day + , subq_10.booking__ds__week AS booking__ds__week + , subq_10.booking__ds__month AS booking__ds__month + , subq_10.booking__ds__quarter AS booking__ds__quarter + , subq_10.booking__ds__year AS booking__ds__year + , subq_10.booking__ds__extract_year AS booking__ds__extract_year + , subq_10.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_10.booking__ds__extract_month AS booking__ds__extract_month + , subq_10.booking__ds__extract_day AS booking__ds__extract_day + , subq_10.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_10.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day AS booking__paid_at__day + , subq_10.booking__paid_at__week AS booking__paid_at__week + , subq_10.booking__paid_at__month AS booking__paid_at__month + , subq_10.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_10.booking__paid_at__year AS booking__paid_at__year + , subq_10.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_10.metric_time__week AS metric_time__week + , subq_10.metric_time__month AS metric_time__month + , subq_10.metric_time__quarter AS metric_time__quarter + , subq_10.metric_time__year AS metric_time__year + , subq_10.metric_time__extract_year AS metric_time__extract_year + , subq_10.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_10.metric_time__extract_month AS metric_time__extract_month + , subq_10.metric_time__extract_day AS metric_time__extract_day + , subq_10.metric_time__extract_dow AS metric_time__extract_dow + , subq_10.metric_time__extract_doy AS metric_time__extract_doy + , subq_13.metric_time__day AS metric_time__day + , subq_10.listing AS listing + , subq_10.guest AS guest + , subq_10.host AS host + , subq_10.booking__listing AS booking__listing + , subq_10.booking__guest AS booking__guest + , subq_10.booking__host AS booking__host + , subq_10.is_instant AS is_instant + , subq_10.booking__is_instant AS booking__is_instant + , subq_10.bookings AS bookings + , subq_10.instant_bookings AS instant_bookings + , subq_10.booking_value AS booking_value + , subq_10.max_booking_value AS max_booking_value + , subq_10.min_booking_value AS min_booking_value + , subq_10.bookers AS bookers + , subq_10.average_booking_value AS average_booking_value + , subq_10.referred_bookings AS referred_bookings + , subq_10.median_booking_value AS median_booking_value + , subq_10.booking_value_p99 AS booking_value_p99 + , subq_10.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_11.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_11 - ) subq_10 + subq_12.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_11 + ) subq_12 + ) subq_13 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -556,18 +600,18 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 + ) subq_9 + ) subq_10 ON - subq_10.metric_time__day - INTERVAL 14 day = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - INTERVAL 14 day = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY - subq_13.metric_time__day - ) subq_14 - ) subq_15 + subq_15.metric_time__day + ) subq_16 + ) subq_17 ON - subq_7.metric_time__day = subq_15.metric_time__day + subq_8.metric_time__day = subq_17.metric_time__day GROUP BY - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) -) subq_16 + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) +) subq_18 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 31ebdbb9f..cdf309495 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_24.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , MAX(subq_32.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_27.metric_time__day, subq_36.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_27.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , MAX(subq_36.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -20,9 +20,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_22.ds AS metric_time__day - , subq_20.bookings AS bookings - FROM ***************************.mf_time_spine subq_22 + time_spine_src_28006.ds AS metric_time__day + , subq_22.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -36,23 +36,23 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_19 + ) subq_21 GROUP BY metric_time__day - ) subq_20 + ) subq_22 ON - subq_22.ds = subq_20.metric_time__day - ) subq_23 - ) subq_24 + time_spine_src_28006.ds = subq_22.metric_time__day + ) subq_26 + ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_28.ds AS metric_time__day - , SUM(subq_26.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_28 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_29.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -60,14 +60,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - subq_28.ds - INTERVAL 14 day = subq_26.metric_time__day + time_spine_src_28006.ds - INTERVAL 14 day = subq_29.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + time_spine_src_28006.ds + ) subq_36 ON - subq_24.metric_time__day = subq_32.metric_time__day + subq_27.metric_time__day = subq_36.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) -) subq_33 + COALESCE(subq_27.metric_time__day, subq_36.metric_time__day) +) subq_37 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index cc87f575c..e61c6560d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_9.metric_time__day + , subq_9.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS metric_time__day - , DATE_TRUNC('month', subq_6.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__day + , subq_6.ds__month + , subq_6.metric_time__day + , subq_6.metric_time__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS metric_time__month + , subq_5.ds__day + , subq_5.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + WHERE (metric_time__day <= '2020-01-02') AND (metric_time__month > '2020-01-01') ) subq_7 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - metric_time__month > '2020-01-01' - ) - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +363,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index 83cb6095e..22b4d8635 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_18.metric_time__day AS metric_time__day + , subq_14.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns SELECT ds AS metric_time__day , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - metric_time__month > '2020-01-01' - ) -) subq_14 + WHERE (metric_time__day <= '2020-01-02') AND (metric_time__month > '2020-01-01') +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -39,10 +37,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('month', ds) AS metric_time__month , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((metric_time__day >= '2020-01-02') AND (metric_time__day <= '2020-01-02')) AND (metric_time__month > '2020-01-01') GROUP BY metric_time__day -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 0c1226247..32956d46d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.booking__ds__day - , subq_8.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_9.booking__ds__day + , subq_9.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( -- Join to Time Spine Dataset SELECT - subq_5.booking__ds__day AS booking__ds__day + subq_8.booking__ds__day AS booking__ds__day , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['booking__ds__day',] SELECT subq_7.booking__ds__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS booking__ds__day - , subq_6.ds AS metric_time__day - , DATE_TRUNC('month', subq_6.ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__day + , subq_6.ds__month + , subq_6.booking__ds__day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS booking__ds__day + , subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS booking__ds__month + , subq_5.ds__day + , subq_5.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + WHERE (metric_time__day <= '2020-01-02') AND (booking__ds__month > '2020-01-01') ) subq_7 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - booking__ds__month > '2020-01-01' - ) - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -342,5 +365,5 @@ FROM ( subq_3.booking__ds__day ) subq_4 ON - subq_5.booking__ds__day = subq_4.booking__ds__day -) subq_8 + subq_8.booking__ds__day = subq_4.booking__ds__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index bbcf6bed7..4925b2418 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.booking__ds__day AS booking__ds__day - , subq_13.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_18.booking__ds__day AS booking__ds__day + , subq_14.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['booking__ds__day',] SELECT booking__ds__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns SELECT ds AS booking__ds__day , ds AS metric_time__day , DATE_TRUNC('month', ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - booking__ds__month > '2020-01-01' - ) -) subq_14 + WHERE (metric_time__day <= '2020-01-02') AND (booking__ds__month > '2020-01-01') +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -41,10 +39,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((metric_time__day >= '2020-01-02') AND (metric_time__day <= '2020-01-02')) AND (booking__ds__month > '2020-01-01') GROUP BY booking__ds__day -) subq_13 +) subq_14 ON - subq_14.booking__ds__day = subq_13.booking__ds__day + subq_18.booking__ds__day = subq_14.booking__ds__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index 6387b7c07..f0f1df7cb 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql @@ -4,30 +4,52 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_9.metric_time__day + , subq_9.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS metric_time__day - , DATE_TRUNC('month', subq_6.ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__day + , subq_6.ds__month + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS booking__ds__month + , subq_5.ds__day + , subq_5.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + WHERE (metric_time__day <= '2020-01-02') AND (booking__ds__month > '2020-01-01') ) subq_7 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - booking__ds__month > '2020-01-01' - ) - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +363,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 56ac28387..c55dfdb34 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_18.metric_time__day AS metric_time__day + , subq_14.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns SELECT ds AS metric_time__day , DATE_TRUNC('month', ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - booking__ds__month > '2020-01-01' - ) -) subq_14 + WHERE (metric_time__day <= '2020-01-02') AND (booking__ds__month > '2020-01-01') +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -39,10 +37,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((metric_time__day >= '2020-01-02') AND (metric_time__day <= '2020-01-02')) AND (booking__ds__month > '2020-01-01') GROUP BY metric_time__day -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index 11529a53f..7490846fb 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.archived_users AS archived_users_join_to_time_spine + subq_9.metric_time__day + , subq_9.archived_users AS archived_users_join_to_time_spine FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.archived_users AS archived_users FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Constrain Output with WHERE SELECT - DATE_TRUNC('day', subq_6.ts) AS metric_time__day - , subq_6.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_6 + subq_6.ts__hour + , subq_6.ts__day + , subq_6.metric_time__day + , subq_6.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ts__day AS metric_time__day + , subq_5.ts__hour AS metric_time__hour + , subq_5.ts__hour + , subq_5.ts__day + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + time_spine_src_28005.ts AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_5 + ) subq_6 + WHERE (metric_time__hour > '2020-01-01 00:09:00') AND (metric_time__day = '2020-01-01') ) subq_7 - WHERE ( - metric_time__hour > '2020-01-01 00:09:00' - ) AND ( - metric_time__day = '2020-01-01' - ) GROUP BY subq_7.metric_time__day - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -618,5 +640,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index 64e5073c7..da330d7b4 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.archived_users AS archived_users_join_to_time_spine + subq_18.metric_time__day AS metric_time__day + , subq_14.archived_users AS archived_users_join_to_time_spine FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine_hour' + -- Transform Time Dimension Columns SELECT DATE_TRUNC('day', ts) AS metric_time__day , ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_15 + FROM ***************************.mf_time_spine_hour time_spine_src_28005 ) subq_16 - WHERE ( - metric_time__hour > '2020-01-01 00:09:00' - ) AND ( - metric_time__day = '2020-01-01' - ) + WHERE (metric_time__hour > '2020-01-01 00:09:00') AND (metric_time__day = '2020-01-01') GROUP BY metric_time__day -) subq_14 +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['archived_users', 'metric_time__day'] @@ -41,10 +39,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('day', archived_at) AS metric_time__day , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_10 + ) subq_11 WHERE (metric_time__hour > '2020-01-01 00:09:00') AND (metric_time__day = '2020-01-01') GROUP BY metric_time__day -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql index 3661b1e49..d7b9ba746 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , COALESCE(subq_10.bookings, 0) AS bookings_fill_nulls_with_0 + subq_12.metric_time__day + , COALESCE(subq_12.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_9.metric_time__day - , subq_9.bookings + subq_11.metric_time__day + , subq_11.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day + subq_10.metric_time__day AS metric_time__day , subq_5.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_8.metric_time__day + subq_9.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_7.ds AS metric_time__day - , DATE_TRUNC('week', subq_7.ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_7 - WHERE subq_7.ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_8 - WHERE metric_time__week > '2020-01-01' - ) subq_6 + subq_8.ds__day + , subq_8.ds__week + , subq_8.metric_time__day + , subq_8.metric_time__week + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.metric_time__day + , subq_7.metric_time__week + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__day + , subq_6.ds__week + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_6 + ) subq_7 + WHERE metric_time__week > '2020-01-01' + ) subq_8 + WHERE subq_8.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' + ) subq_9 + ) subq_10 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -446,7 +480,7 @@ FROM ( subq_4.metric_time__day ) subq_5 ON - subq_6.metric_time__day = subq_5.metric_time__day - ) subq_9 - WHERE subq_9.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_10 + subq_10.metric_time__day = subq_5.metric_time__day + ) subq_11 + WHERE subq_11.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_12 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql index 289c4bd7a..b486d4a12 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql @@ -10,22 +10,28 @@ FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_17.metric_time__day AS metric_time__day - , subq_16.bookings AS bookings + subq_23.metric_time__day AS metric_time__day + , subq_18.bookings AS bookings FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns SELECT ds AS metric_time__day , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_18 - WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_19 - WHERE metric_time__week > '2020-01-01' - ) subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_20 + WHERE ( + metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' + ) AND ( + metric_time__week > '2020-01-01' + ) + ) subq_23 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -43,12 +49,12 @@ FROM ( , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_13 + ) subq_15 WHERE metric_time__week > '2020-01-01' GROUP BY metric_time__day - ) subq_16 + ) subq_18 ON - subq_17.metric_time__day = subq_16.metric_time__day - WHERE subq_17.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_21 + subq_23.metric_time__day = subq_18.metric_time__day + WHERE subq_23.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_25 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql index 2aa9af4a1..05cf9d9e9 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 + subq_7.metric_time__day + , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ds__day AS metric_time__day + , subq_4.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +249,5 @@ FROM ( subq_2.metric_time__day ) subq_3 ON - subq_4.metric_time__day = subq_3.metric_time__day -) subq_6 + subq_6.metric_time__day = subq_3.metric_time__day +) subq_7 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index 30f3bf383..2f994958d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_12.ds AS metric_time__day - , subq_10.bookings AS bookings - FROM ***************************.mf_time_spine subq_12 + time_spine_src_28006.ds AS metric_time__day + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -25,10 +25,10 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__day - ) subq_10 + ) subq_11 ON - subq_12.ds = subq_10.metric_time__day -) subq_13 + time_spine_src_28006.ds = subq_11.metric_time__day +) subq_15 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql index 4263d4c10..bc2012ed5 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__month - , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 + subq_7.metric_time__month + , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__month AS metric_time__month + subq_6.metric_time__month AS metric_time__month , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__month',] SELECT - DATE_TRUNC('month', subq_5.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_5 + subq_5.metric_time__month + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ds__month AS metric_time__month + , subq_4.ds__month + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_4 + ) subq_5 GROUP BY - DATE_TRUNC('month', subq_5.ds) - ) subq_4 + subq_5.metric_time__month + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -229,5 +251,5 @@ FROM ( subq_2.metric_time__month ) subq_3 ON - subq_4.metric_time__month = subq_3.metric_time__month -) subq_6 + subq_6.metric_time__month = subq_3.metric_time__month +) subq_7 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index 2eaeedf47..0f6d1ad41 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql @@ -9,16 +9,18 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_11.metric_time__month AS metric_time__month - , subq_10.bookings AS bookings + subq_14.metric_time__month AS metric_time__month + , subq_11.bookings AS bookings FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Pass Only Elements: ['metric_time__month',] SELECT DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY DATE_TRUNC('month', ds) - ) subq_11 + ) subq_14 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -32,10 +34,10 @@ FROM ( DATE_TRUNC('month', ds) AS metric_time__month , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__month - ) subq_10 + ) subq_11 ON - subq_11.metric_time__month = subq_10.metric_time__month -) subq_13 + subq_14.metric_time__month = subq_11.metric_time__month +) subq_15 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql index 95501d310..26c3dd77d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__extract_dow + subq_14.metric_time__extract_dow , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__extract_dow, subq_12.metric_time__extract_dow) AS metric_time__extract_dow + COALESCE(subq_4.metric_time__extract_dow, subq_13.metric_time__extract_dow) AS metric_time__extract_dow , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__extract_dow - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.metric_time__extract_dow + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__extract_dow - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__extract_dow + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] SELECT - subq_9.metric_time__extract_dow - , subq_9.bookings + subq_10.metric_time__extract_dow + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -320,8 +320,8 @@ FROM ( , subq_6.metric_time__extract_month AS metric_time__extract_month , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__extract_dow AS metric_time__extract_dow + , subq_9.metric_time__day AS metric_time__day + , subq_9.metric_time__extract_dow AS metric_time__extract_dow , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,12 +344,36 @@ FROM ( , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__extract_dow'] SELECT - subq_8.ds AS metric_time__day - , EXTRACT(isodow FROM subq_8.ds) AS metric_time__extract_dow - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + , subq_8.metric_time__extract_dow + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , subq_7.ds__day + , subq_7.ds__extract_dow + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +570,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__extract_dow - ) subq_11 - ) subq_12 + subq_11.metric_time__extract_dow + ) subq_12 + ) subq_13 ON - subq_4.metric_time__extract_dow = subq_12.metric_time__extract_dow + subq_4.metric_time__extract_dow = subq_13.metric_time__extract_dow GROUP BY - COALESCE(subq_4.metric_time__extract_dow, subq_12.metric_time__extract_dow) -) subq_13 + COALESCE(subq_4.metric_time__extract_dow, subq_13.metric_time__extract_dow) +) subq_14 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql index 475bffcec..79f6aef9b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__extract_dow, subq_26.metric_time__extract_dow) AS metric_time__extract_dow - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__extract_dow, subq_28.metric_time__extract_dow) AS metric_time__extract_dow + , MAX(subq_19.bookings) AS bookings + , MAX(subq_28.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -26,19 +26,19 @@ FROM ( EXTRACT(isodow FROM ds) AS metric_time__extract_dow , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_17 GROUP BY metric_time__extract_dow - ) subq_18 + ) subq_19 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - EXTRACT(isodow FROM subq_22.ds) AS metric_time__extract_dow - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + EXTRACT(isodow FROM time_spine_src_28006.ds) AS metric_time__extract_dow + , SUM(subq_21.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + time_spine_src_28006.ds - INTERVAL 14 day = subq_21.metric_time__day GROUP BY - EXTRACT(isodow FROM subq_22.ds) - ) subq_26 + EXTRACT(isodow FROM time_spine_src_28006.ds) + ) subq_28 ON - subq_18.metric_time__extract_dow = subq_26.metric_time__extract_dow + subq_19.metric_time__extract_dow = subq_28.metric_time__extract_dow GROUP BY - COALESCE(subq_18.metric_time__extract_dow, subq_26.metric_time__extract_dow) -) subq_27 + COALESCE(subq_19.metric_time__extract_dow, subq_28.metric_time__extract_dow) +) subq_29 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index ea985a35d..97979a296 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users AS subdaily_join_to_time_spine_metric + subq_7.metric_time__hour + , subq_7.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__hour AS metric_time__hour + subq_6.metric_time__hour AS metric_time__hour , subq_3.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour',] SELECT - subq_5.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_5 - ) subq_4 + subq_5.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__hour + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + time_spine_src_28005.ts AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -410,5 +432,5 @@ FROM ( subq_2.metric_time__hour ) subq_3 ON - subq_4.metric_time__hour = subq_3.metric_time__hour -) subq_6 + subq_6.metric_time__hour = subq_3.metric_time__hour +) subq_7 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index cb9fd532c..ea9ced6c5 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ts AS metric_time__hour - , subq_10.archived_users AS subdaily_join_to_time_spine_metric -FROM ***************************.mf_time_spine_hour subq_12 + time_spine_src_28005.ts AS metric_time__hour + , subq_11.archived_users AS subdaily_join_to_time_spine_metric +FROM ***************************.mf_time_spine_hour time_spine_src_28005 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -21,9 +21,9 @@ LEFT OUTER JOIN ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__hour -) subq_10 +) subq_11 ON - subq_12.ts = subq_10.metric_time__hour + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql index 8acb3f0a5..6bfb266bd 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users AS subdaily_join_to_time_spine_metric + subq_7.metric_time__hour + , subq_7.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__hour AS metric_time__hour + subq_6.metric_time__hour AS metric_time__hour , subq_3.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour',] SELECT - subq_5.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_5 - ) subq_4 + subq_5.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__hour + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + time_spine_src_28005.ts AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -410,5 +432,5 @@ FROM ( subq_2.metric_time__hour ) subq_3 ON - subq_4.metric_time__hour = subq_3.metric_time__hour -) subq_6 + subq_6.metric_time__hour = subq_3.metric_time__hour +) subq_7 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index de002a8a6..e30c1c235 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ts AS metric_time__hour - , subq_10.archived_users AS subdaily_join_to_time_spine_metric -FROM ***************************.mf_time_spine_hour subq_12 + time_spine_src_28005.ts AS metric_time__hour + , subq_11.archived_users AS subdaily_join_to_time_spine_metric +FROM ***************************.mf_time_spine_hour time_spine_src_28005 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -21,9 +21,9 @@ LEFT OUTER JOIN ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__hour -) subq_10 +) subq_11 ON - subq_12.ts = subq_10.metric_time__hour + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql index 80237f265..46c51280e 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__hour + subq_8.metric_time__hour , archived_users AS subdaily_offset_grain_to_date_metric FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users + subq_7.metric_time__hour + , subq_7.archived_users FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__hour - , SUM(subq_5.archived_users) AS archived_users + subq_6.metric_time__hour + , SUM(subq_6.archived_users) AS archived_users FROM ( -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_4.metric_time__hour - , subq_4.archived_users + subq_5.metric_time__hour + , subq_5.archived_users FROM ( -- Join to Time Spine Dataset SELECT @@ -209,17 +209,39 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__hour AS metric_time__hour + , subq_4.metric_time__hour AS metric_time__hour , subq_1.user AS user , subq_1.home_state AS home_state , subq_1.user__home_state AS user__home_state , subq_1.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour', 'metric_time__hour'] SELECT - subq_3.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_3 - ) subq_2 + subq_3.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__hour + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + time_spine_src_28005.ts AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'archived_at' SELECT @@ -599,10 +621,10 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('hour', subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATE_TRUNC('hour', subq_4.metric_time__hour) = subq_1.metric_time__hour + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__hour - ) subq_6 -) subq_7 + subq_6.metric_time__hour + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index a13ee4f4c..d1809f303 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql @@ -12,9 +12,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ts AS metric_time__hour - , SUM(subq_9.archived_users) AS archived_users - FROM ***************************.mf_time_spine_hour subq_11 + time_spine_src_28005.ts AS metric_time__hour + , SUM(subq_10.archived_users) AS archived_users + FROM ***************************.mf_time_spine_hour time_spine_src_28005 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -22,9 +22,9 @@ FROM ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 ON - DATE_TRUNC('hour', subq_11.ts) = subq_9.metric_time__hour + DATE_TRUNC('hour', time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql index 5caa97f29..6dfe1257a 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__hour + subq_8.metric_time__hour , archived_users AS subdaily_offset_window_metric FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users + subq_7.metric_time__hour + , subq_7.archived_users FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__hour - , SUM(subq_5.archived_users) AS archived_users + subq_6.metric_time__hour + , SUM(subq_6.archived_users) AS archived_users FROM ( -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_4.metric_time__hour - , subq_4.archived_users + subq_5.metric_time__hour + , subq_5.archived_users FROM ( -- Join to Time Spine Dataset SELECT @@ -209,17 +209,39 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__hour AS metric_time__hour + , subq_4.metric_time__hour AS metric_time__hour , subq_1.user AS user , subq_1.home_state AS home_state , subq_1.user__home_state AS user__home_state , subq_1.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour', 'metric_time__hour'] SELECT - subq_3.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_3 - ) subq_2 + subq_3.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__hour + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + time_spine_src_28005.ts AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'archived_at' SELECT @@ -599,10 +621,10 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__hour - INTERVAL 1 hour = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + subq_4.metric_time__hour - INTERVAL 1 hour = subq_1.metric_time__hour + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__hour - ) subq_6 -) subq_7 + subq_6.metric_time__hour + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql index 78923e04e..7d57881f4 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql @@ -12,9 +12,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ts AS metric_time__hour - , SUM(subq_9.archived_users) AS archived_users - FROM ***************************.mf_time_spine_hour subq_11 + time_spine_src_28005.ts AS metric_time__hour + , SUM(subq_10.archived_users) AS archived_users + FROM ***************************.mf_time_spine_hour time_spine_src_28005 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -22,9 +22,9 @@ FROM ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 ON - subq_11.ts - INTERVAL 1 hour = subq_9.metric_time__hour + time_spine_src_28005.ts - INTERVAL 1 hour = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql index 73bd49f0a..f7089fb16 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__hour - , subq_8.archived_users AS subdaily_join_to_time_spine_metric + subq_10.metric_time__hour + , subq_10.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] SELECT - subq_7.metric_time__hour - , subq_7.archived_users + subq_9.metric_time__hour + , subq_9.archived_users FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__hour AS metric_time__hour + subq_8.metric_time__hour AS metric_time__hour , subq_4.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour',] SELECT - subq_6.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_6 - WHERE subq_6.ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' - ) subq_5 + subq_7.metric_time__hour + FROM ( + -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] + SELECT + subq_6.ts__hour + , subq_6.metric_time__hour + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ts__hour AS metric_time__hour + , subq_5.ts__hour + FROM ( + -- Read From Time Spine 'mf_time_spine_hour' + SELECT + time_spine_src_28005.ts AS ts__hour + , DATE_TRUNC('day', time_spine_src_28005.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28005.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28005.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28005.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28005.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28005.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28005.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28005.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28005.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28005.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28005.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_hour time_spine_src_28005 + ) subq_5 + ) subq_6 + WHERE subq_6.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' + ) subq_7 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -611,7 +639,7 @@ FROM ( subq_3.metric_time__hour ) subq_4 ON - subq_5.metric_time__hour = subq_4.metric_time__hour - ) subq_7 - WHERE subq_7.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' -) subq_8 + subq_8.metric_time__hour = subq_4.metric_time__hour + ) subq_9 + WHERE subq_9.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' +) subq_10 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index c12dd7b5e..88b189943 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: DuckDB -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] -- Compute Metrics via Expressions SELECT - subq_14.metric_time__hour AS metric_time__hour - , subq_13.archived_users AS subdaily_join_to_time_spine_metric + subq_19.metric_time__hour AS metric_time__hour + , subq_15.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Read From Time Spine 'mf_time_spine_hour' + -- Transform Time Dimension Columns + -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] + -- Pass Only Elements: ['metric_time__hour',] SELECT ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_15 + FROM ***************************.mf_time_spine_hour time_spine_src_28005 WHERE ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' -) subq_14 +) subq_19 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -30,10 +33,10 @@ LEFT OUTER JOIN ( , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 WHERE DATE_TRUNC('hour', archived_at) BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' - ) subq_12 + ) subq_14 GROUP BY metric_time__hour -) subq_13 +) subq_15 ON - subq_14.metric_time__hour = subq_13.metric_time__hour -WHERE subq_14.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' + subq_19.metric_time__hour = subq_15.metric_time__hour +WHERE subq_19.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml index 3155d70d4..c170a314b 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml @@ -128,6 +128,11 @@ docstring: + + + + + @@ -296,6 +301,11 @@ docstring: + + + + + @@ -303,7 +313,7 @@ docstring: - + @@ -361,9 +371,9 @@ docstring: - + - + @@ -380,6 +390,14 @@ docstring: + + + + + + + + @@ -396,7 +414,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml index b18699c1e..80622c0cf 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml @@ -128,6 +128,11 @@ docstring: + + + + + @@ -135,7 +140,7 @@ docstring: - + @@ -151,9 +156,9 @@ docstring: - + - + @@ -212,7 +217,7 @@ docstring: - + @@ -295,6 +300,11 @@ docstring: + + + + + @@ -302,7 +312,7 @@ docstring: - + @@ -360,9 +370,9 @@ docstring: - + - + @@ -379,6 +389,14 @@ docstring: + + + + + + + + @@ -395,7 +413,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml index 00cb1d56f..23fbea8f6 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml @@ -177,6 +177,11 @@ docstring: + + + + + @@ -396,6 +401,11 @@ docstring: + + + + + @@ -404,7 +414,7 @@ docstring: - + @@ -467,9 +477,9 @@ docstring: - + - + @@ -486,6 +496,14 @@ docstring: + + + + + + + + @@ -502,7 +520,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml index 4a805d22f..caa0a3619 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml @@ -177,6 +177,11 @@ docstring: + + + + + @@ -185,7 +190,7 @@ docstring: - + @@ -206,9 +211,9 @@ docstring: - + - + @@ -268,7 +273,7 @@ docstring: - + @@ -396,6 +401,11 @@ docstring: + + + + + @@ -404,7 +414,7 @@ docstring: - + @@ -467,9 +477,9 @@ docstring: - + - + @@ -486,6 +496,14 @@ docstring: + + + + + + + + @@ -502,7 +520,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml index 9f0b5af2d..d3d131378 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml @@ -280,7 +280,7 @@ docstring: - + @@ -338,9 +338,9 @@ docstring: - + - + @@ -357,6 +357,14 @@ docstring: + + + + + + + + @@ -372,7 +380,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml index 3d4c78b8d..ed7e2148c 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml @@ -125,7 +125,7 @@ docstring: - + @@ -141,9 +141,9 @@ docstring: - + - + @@ -202,7 +202,7 @@ docstring: - + @@ -280,7 +280,7 @@ docstring: - + @@ -338,9 +338,9 @@ docstring: - + - + @@ -357,6 +357,14 @@ docstring: + + + + + + + + @@ -372,7 +380,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index 5b4e43f97..ef528b6b8 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_29.metric_time__day - , subq_29.listing__country_latest + subq_32.metric_time__day + , subq_32.listing__country_latest , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0 FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_12.metric_time__day, subq_28.metric_time__day) AS metric_time__day - , COALESCE(subq_12.listing__country_latest, subq_28.listing__country_latest) AS listing__country_latest - , COALESCE(MAX(subq_12.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , COALESCE(MAX(subq_28.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_13.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , COALESCE(subq_13.listing__country_latest, subq_31.listing__country_latest) AS listing__country_latest + , COALESCE(MAX(subq_13.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , COALESCE(MAX(subq_31.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.listing__country_latest - , COALESCE(subq_11.bookings, 0) AS bookings_fill_nulls_with_0 + subq_12.metric_time__day + , subq_12.listing__country_latest + , COALESCE(subq_12.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day + subq_11.metric_time__day AS metric_time__day , subq_8.listing__country_latest AS listing__country_latest , subq_8.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_10.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_9.ds__day AS metric_time__day + , subq_9.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -596,451 +618,495 @@ FROM ( , subq_7.listing__country_latest ) subq_8 ON - subq_9.metric_time__day = subq_8.metric_time__day - ) subq_11 - ) subq_12 + subq_11.metric_time__day = subq_8.metric_time__day + ) subq_12 + ) subq_13 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_27.metric_time__day - , subq_27.listing__country_latest - , COALESCE(subq_27.bookings, 0) AS bookings_2_weeks_ago + subq_30.metric_time__day + , subq_30.listing__country_latest + , COALESCE(subq_30.bookings, 0) AS bookings_2_weeks_ago FROM ( -- Join to Time Spine Dataset SELECT - subq_25.metric_time__day AS metric_time__day - , subq_24.listing__country_latest AS listing__country_latest - , subq_24.bookings AS bookings + subq_29.metric_time__day AS metric_time__day + , subq_26.listing__country_latest AS listing__country_latest + , subq_26.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_26.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_26 - ) subq_25 + subq_28.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_27.ds__day AS metric_time__day + , subq_27.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_27 + ) subq_28 + ) subq_29 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_23.metric_time__day - , subq_23.listing__country_latest - , SUM(subq_23.bookings) AS bookings + subq_25.metric_time__day + , subq_25.listing__country_latest + , SUM(subq_25.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] SELECT - subq_22.metric_time__day - , subq_22.listing__country_latest - , subq_22.bookings + subq_24.metric_time__day + , subq_24.listing__country_latest + , subq_24.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_21.metric_time__day - , subq_21.ds__day - , subq_21.ds__week - , subq_21.ds__month - , subq_21.ds__quarter - , subq_21.ds__year - , subq_21.ds__extract_year - , subq_21.ds__extract_quarter - , subq_21.ds__extract_month - , subq_21.ds__extract_day - , subq_21.ds__extract_dow - , subq_21.ds__extract_doy - , subq_21.ds_partitioned__day - , subq_21.ds_partitioned__week - , subq_21.ds_partitioned__month - , subq_21.ds_partitioned__quarter - , subq_21.ds_partitioned__year - , subq_21.ds_partitioned__extract_year - , subq_21.ds_partitioned__extract_quarter - , subq_21.ds_partitioned__extract_month - , subq_21.ds_partitioned__extract_day - , subq_21.ds_partitioned__extract_dow - , subq_21.ds_partitioned__extract_doy - , subq_21.paid_at__day - , subq_21.paid_at__week - , subq_21.paid_at__month - , subq_21.paid_at__quarter - , subq_21.paid_at__year - , subq_21.paid_at__extract_year - , subq_21.paid_at__extract_quarter - , subq_21.paid_at__extract_month - , subq_21.paid_at__extract_day - , subq_21.paid_at__extract_dow - , subq_21.paid_at__extract_doy - , subq_21.booking__ds__day - , subq_21.booking__ds__week - , subq_21.booking__ds__month - , subq_21.booking__ds__quarter - , subq_21.booking__ds__year - , subq_21.booking__ds__extract_year - , subq_21.booking__ds__extract_quarter - , subq_21.booking__ds__extract_month - , subq_21.booking__ds__extract_day - , subq_21.booking__ds__extract_dow - , subq_21.booking__ds__extract_doy - , subq_21.booking__ds_partitioned__day - , subq_21.booking__ds_partitioned__week - , subq_21.booking__ds_partitioned__month - , subq_21.booking__ds_partitioned__quarter - , subq_21.booking__ds_partitioned__year - , subq_21.booking__ds_partitioned__extract_year - , subq_21.booking__ds_partitioned__extract_quarter - , subq_21.booking__ds_partitioned__extract_month - , subq_21.booking__ds_partitioned__extract_day - , subq_21.booking__ds_partitioned__extract_dow - , subq_21.booking__ds_partitioned__extract_doy - , subq_21.booking__paid_at__day - , subq_21.booking__paid_at__week - , subq_21.booking__paid_at__month - , subq_21.booking__paid_at__quarter - , subq_21.booking__paid_at__year - , subq_21.booking__paid_at__extract_year - , subq_21.booking__paid_at__extract_quarter - , subq_21.booking__paid_at__extract_month - , subq_21.booking__paid_at__extract_day - , subq_21.booking__paid_at__extract_dow - , subq_21.booking__paid_at__extract_doy - , subq_21.metric_time__week - , subq_21.metric_time__month - , subq_21.metric_time__quarter - , subq_21.metric_time__year - , subq_21.metric_time__extract_year - , subq_21.metric_time__extract_quarter - , subq_21.metric_time__extract_month - , subq_21.metric_time__extract_day - , subq_21.metric_time__extract_dow - , subq_21.metric_time__extract_doy - , subq_21.listing - , subq_21.guest - , subq_21.host - , subq_21.booking__listing - , subq_21.booking__guest - , subq_21.booking__host - , subq_21.is_instant - , subq_21.booking__is_instant - , subq_21.listing__country_latest - , subq_21.bookings - , subq_21.instant_bookings - , subq_21.booking_value - , subq_21.max_booking_value - , subq_21.min_booking_value - , subq_21.bookers - , subq_21.average_booking_value - , subq_21.referred_bookings - , subq_21.median_booking_value - , subq_21.booking_value_p99 - , subq_21.discrete_booking_value_p99 - , subq_21.approximate_continuous_booking_value_p99 - , subq_21.approximate_discrete_booking_value_p99 + subq_23.ds__day + , subq_23.ds__week + , subq_23.ds__month + , subq_23.ds__quarter + , subq_23.ds__year + , subq_23.ds__extract_year + , subq_23.ds__extract_quarter + , subq_23.ds__extract_month + , subq_23.ds__extract_day + , subq_23.ds__extract_dow + , subq_23.ds__extract_doy + , subq_23.ds_partitioned__day + , subq_23.ds_partitioned__week + , subq_23.ds_partitioned__month + , subq_23.ds_partitioned__quarter + , subq_23.ds_partitioned__year + , subq_23.ds_partitioned__extract_year + , subq_23.ds_partitioned__extract_quarter + , subq_23.ds_partitioned__extract_month + , subq_23.ds_partitioned__extract_day + , subq_23.ds_partitioned__extract_dow + , subq_23.ds_partitioned__extract_doy + , subq_23.paid_at__day + , subq_23.paid_at__week + , subq_23.paid_at__month + , subq_23.paid_at__quarter + , subq_23.paid_at__year + , subq_23.paid_at__extract_year + , subq_23.paid_at__extract_quarter + , subq_23.paid_at__extract_month + , subq_23.paid_at__extract_day + , subq_23.paid_at__extract_dow + , subq_23.paid_at__extract_doy + , subq_23.booking__ds__day + , subq_23.booking__ds__week + , subq_23.booking__ds__month + , subq_23.booking__ds__quarter + , subq_23.booking__ds__year + , subq_23.booking__ds__extract_year + , subq_23.booking__ds__extract_quarter + , subq_23.booking__ds__extract_month + , subq_23.booking__ds__extract_day + , subq_23.booking__ds__extract_dow + , subq_23.booking__ds__extract_doy + , subq_23.booking__ds_partitioned__day + , subq_23.booking__ds_partitioned__week + , subq_23.booking__ds_partitioned__month + , subq_23.booking__ds_partitioned__quarter + , subq_23.booking__ds_partitioned__year + , subq_23.booking__ds_partitioned__extract_year + , subq_23.booking__ds_partitioned__extract_quarter + , subq_23.booking__ds_partitioned__extract_month + , subq_23.booking__ds_partitioned__extract_day + , subq_23.booking__ds_partitioned__extract_dow + , subq_23.booking__ds_partitioned__extract_doy + , subq_23.booking__paid_at__day + , subq_23.booking__paid_at__week + , subq_23.booking__paid_at__month + , subq_23.booking__paid_at__quarter + , subq_23.booking__paid_at__year + , subq_23.booking__paid_at__extract_year + , subq_23.booking__paid_at__extract_quarter + , subq_23.booking__paid_at__extract_month + , subq_23.booking__paid_at__extract_day + , subq_23.booking__paid_at__extract_dow + , subq_23.booking__paid_at__extract_doy + , subq_23.metric_time__week + , subq_23.metric_time__month + , subq_23.metric_time__quarter + , subq_23.metric_time__year + , subq_23.metric_time__extract_year + , subq_23.metric_time__extract_quarter + , subq_23.metric_time__extract_month + , subq_23.metric_time__extract_day + , subq_23.metric_time__extract_dow + , subq_23.metric_time__extract_doy + , subq_23.metric_time__day + , subq_23.listing + , subq_23.guest + , subq_23.host + , subq_23.booking__listing + , subq_23.booking__guest + , subq_23.booking__host + , subq_23.is_instant + , subq_23.booking__is_instant + , subq_23.listing__country_latest + , subq_23.bookings + , subq_23.instant_bookings + , subq_23.booking_value + , subq_23.max_booking_value + , subq_23.min_booking_value + , subq_23.bookers + , subq_23.average_booking_value + , subq_23.referred_bookings + , subq_23.median_booking_value + , subq_23.booking_value_p99 + , subq_23.discrete_booking_value_p99 + , subq_23.approximate_continuous_booking_value_p99 + , subq_23.approximate_discrete_booking_value_p99 FROM ( -- Join Standard Outputs SELECT - subq_20.country_latest AS listing__country_latest - , subq_17.metric_time__day AS metric_time__day - , subq_17.ds__day AS ds__day - , subq_17.ds__week AS ds__week - , subq_17.ds__month AS ds__month - , subq_17.ds__quarter AS ds__quarter - , subq_17.ds__year AS ds__year - , subq_17.ds__extract_year AS ds__extract_year - , subq_17.ds__extract_quarter AS ds__extract_quarter - , subq_17.ds__extract_month AS ds__extract_month - , subq_17.ds__extract_day AS ds__extract_day - , subq_17.ds__extract_dow AS ds__extract_dow - , subq_17.ds__extract_doy AS ds__extract_doy - , subq_17.ds_partitioned__day AS ds_partitioned__day - , subq_17.ds_partitioned__week AS ds_partitioned__week - , subq_17.ds_partitioned__month AS ds_partitioned__month - , subq_17.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_17.ds_partitioned__year AS ds_partitioned__year - , subq_17.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_17.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_17.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_17.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_17.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_17.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_17.paid_at__day AS paid_at__day - , subq_17.paid_at__week AS paid_at__week - , subq_17.paid_at__month AS paid_at__month - , subq_17.paid_at__quarter AS paid_at__quarter - , subq_17.paid_at__year AS paid_at__year - , subq_17.paid_at__extract_year AS paid_at__extract_year - , subq_17.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_17.paid_at__extract_month AS paid_at__extract_month - , subq_17.paid_at__extract_day AS paid_at__extract_day - , subq_17.paid_at__extract_dow AS paid_at__extract_dow - , subq_17.paid_at__extract_doy AS paid_at__extract_doy - , subq_17.booking__ds__day AS booking__ds__day - , subq_17.booking__ds__week AS booking__ds__week - , subq_17.booking__ds__month AS booking__ds__month - , subq_17.booking__ds__quarter AS booking__ds__quarter - , subq_17.booking__ds__year AS booking__ds__year - , subq_17.booking__ds__extract_year AS booking__ds__extract_year - , subq_17.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_17.booking__ds__extract_month AS booking__ds__extract_month - , subq_17.booking__ds__extract_day AS booking__ds__extract_day - , subq_17.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_17.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_17.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_17.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_17.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_17.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_17.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_17.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_17.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_17.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_17.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_17.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_17.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_17.booking__paid_at__day AS booking__paid_at__day - , subq_17.booking__paid_at__week AS booking__paid_at__week - , subq_17.booking__paid_at__month AS booking__paid_at__month - , subq_17.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_17.booking__paid_at__year AS booking__paid_at__year - , subq_17.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_17.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_17.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_17.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_17.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_17.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_17.metric_time__week AS metric_time__week - , subq_17.metric_time__month AS metric_time__month - , subq_17.metric_time__quarter AS metric_time__quarter - , subq_17.metric_time__year AS metric_time__year - , subq_17.metric_time__extract_year AS metric_time__extract_year - , subq_17.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_17.metric_time__extract_month AS metric_time__extract_month - , subq_17.metric_time__extract_day AS metric_time__extract_day - , subq_17.metric_time__extract_dow AS metric_time__extract_dow - , subq_17.metric_time__extract_doy AS metric_time__extract_doy - , subq_17.listing AS listing - , subq_17.guest AS guest - , subq_17.host AS host - , subq_17.booking__listing AS booking__listing - , subq_17.booking__guest AS booking__guest - , subq_17.booking__host AS booking__host - , subq_17.is_instant AS is_instant - , subq_17.booking__is_instant AS booking__is_instant - , subq_17.bookings AS bookings - , subq_17.instant_bookings AS instant_bookings - , subq_17.booking_value AS booking_value - , subq_17.max_booking_value AS max_booking_value - , subq_17.min_booking_value AS min_booking_value - , subq_17.bookers AS bookers - , subq_17.average_booking_value AS average_booking_value - , subq_17.referred_bookings AS referred_bookings - , subq_17.median_booking_value AS median_booking_value - , subq_17.booking_value_p99 AS booking_value_p99 - , subq_17.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_17.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_17.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_22.country_latest AS listing__country_latest + , subq_19.ds__day AS ds__day + , subq_19.ds__week AS ds__week + , subq_19.ds__month AS ds__month + , subq_19.ds__quarter AS ds__quarter + , subq_19.ds__year AS ds__year + , subq_19.ds__extract_year AS ds__extract_year + , subq_19.ds__extract_quarter AS ds__extract_quarter + , subq_19.ds__extract_month AS ds__extract_month + , subq_19.ds__extract_day AS ds__extract_day + , subq_19.ds__extract_dow AS ds__extract_dow + , subq_19.ds__extract_doy AS ds__extract_doy + , subq_19.ds_partitioned__day AS ds_partitioned__day + , subq_19.ds_partitioned__week AS ds_partitioned__week + , subq_19.ds_partitioned__month AS ds_partitioned__month + , subq_19.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_19.ds_partitioned__year AS ds_partitioned__year + , subq_19.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_19.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_19.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_19.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_19.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_19.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_19.paid_at__day AS paid_at__day + , subq_19.paid_at__week AS paid_at__week + , subq_19.paid_at__month AS paid_at__month + , subq_19.paid_at__quarter AS paid_at__quarter + , subq_19.paid_at__year AS paid_at__year + , subq_19.paid_at__extract_year AS paid_at__extract_year + , subq_19.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_19.paid_at__extract_month AS paid_at__extract_month + , subq_19.paid_at__extract_day AS paid_at__extract_day + , subq_19.paid_at__extract_dow AS paid_at__extract_dow + , subq_19.paid_at__extract_doy AS paid_at__extract_doy + , subq_19.booking__ds__day AS booking__ds__day + , subq_19.booking__ds__week AS booking__ds__week + , subq_19.booking__ds__month AS booking__ds__month + , subq_19.booking__ds__quarter AS booking__ds__quarter + , subq_19.booking__ds__year AS booking__ds__year + , subq_19.booking__ds__extract_year AS booking__ds__extract_year + , subq_19.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_19.booking__ds__extract_month AS booking__ds__extract_month + , subq_19.booking__ds__extract_day AS booking__ds__extract_day + , subq_19.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_19.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_19.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_19.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_19.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_19.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_19.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_19.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_19.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_19.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_19.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_19.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_19.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_19.booking__paid_at__day AS booking__paid_at__day + , subq_19.booking__paid_at__week AS booking__paid_at__week + , subq_19.booking__paid_at__month AS booking__paid_at__month + , subq_19.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_19.booking__paid_at__year AS booking__paid_at__year + , subq_19.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_19.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_19.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_19.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_19.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_19.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_19.metric_time__week AS metric_time__week + , subq_19.metric_time__month AS metric_time__month + , subq_19.metric_time__quarter AS metric_time__quarter + , subq_19.metric_time__year AS metric_time__year + , subq_19.metric_time__extract_year AS metric_time__extract_year + , subq_19.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_19.metric_time__extract_month AS metric_time__extract_month + , subq_19.metric_time__extract_day AS metric_time__extract_day + , subq_19.metric_time__extract_dow AS metric_time__extract_dow + , subq_19.metric_time__extract_doy AS metric_time__extract_doy + , subq_19.metric_time__day AS metric_time__day + , subq_19.listing AS listing + , subq_19.guest AS guest + , subq_19.host AS host + , subq_19.booking__listing AS booking__listing + , subq_19.booking__guest AS booking__guest + , subq_19.booking__host AS booking__host + , subq_19.is_instant AS is_instant + , subq_19.booking__is_instant AS booking__is_instant + , subq_19.bookings AS bookings + , subq_19.instant_bookings AS instant_bookings + , subq_19.booking_value AS booking_value + , subq_19.max_booking_value AS max_booking_value + , subq_19.min_booking_value AS min_booking_value + , subq_19.bookers AS bookers + , subq_19.average_booking_value AS average_booking_value + , subq_19.referred_bookings AS referred_bookings + , subq_19.median_booking_value AS median_booking_value + , subq_19.booking_value_p99 AS booking_value_p99 + , subq_19.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_19.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_19.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT - subq_14.ds__day AS ds__day - , subq_14.ds__week AS ds__week - , subq_14.ds__month AS ds__month - , subq_14.ds__quarter AS ds__quarter - , subq_14.ds__year AS ds__year - , subq_14.ds__extract_year AS ds__extract_year - , subq_14.ds__extract_quarter AS ds__extract_quarter - , subq_14.ds__extract_month AS ds__extract_month - , subq_14.ds__extract_day AS ds__extract_day - , subq_14.ds__extract_dow AS ds__extract_dow - , subq_14.ds__extract_doy AS ds__extract_doy - , subq_14.ds_partitioned__day AS ds_partitioned__day - , subq_14.ds_partitioned__week AS ds_partitioned__week - , subq_14.ds_partitioned__month AS ds_partitioned__month - , subq_14.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_14.ds_partitioned__year AS ds_partitioned__year - , subq_14.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_14.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_14.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_14.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_14.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_14.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_14.paid_at__day AS paid_at__day - , subq_14.paid_at__week AS paid_at__week - , subq_14.paid_at__month AS paid_at__month - , subq_14.paid_at__quarter AS paid_at__quarter - , subq_14.paid_at__year AS paid_at__year - , subq_14.paid_at__extract_year AS paid_at__extract_year - , subq_14.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_14.paid_at__extract_month AS paid_at__extract_month - , subq_14.paid_at__extract_day AS paid_at__extract_day - , subq_14.paid_at__extract_dow AS paid_at__extract_dow - , subq_14.paid_at__extract_doy AS paid_at__extract_doy - , subq_14.booking__ds__day AS booking__ds__day - , subq_14.booking__ds__week AS booking__ds__week - , subq_14.booking__ds__month AS booking__ds__month - , subq_14.booking__ds__quarter AS booking__ds__quarter - , subq_14.booking__ds__year AS booking__ds__year - , subq_14.booking__ds__extract_year AS booking__ds__extract_year - , subq_14.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_14.booking__ds__extract_month AS booking__ds__extract_month - , subq_14.booking__ds__extract_day AS booking__ds__extract_day - , subq_14.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_14.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_14.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_14.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_14.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_14.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_14.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_14.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_14.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_14.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_14.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_14.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_14.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_14.booking__paid_at__day AS booking__paid_at__day - , subq_14.booking__paid_at__week AS booking__paid_at__week - , subq_14.booking__paid_at__month AS booking__paid_at__month - , subq_14.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_14.booking__paid_at__year AS booking__paid_at__year - , subq_14.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_14.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_14.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_14.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_14.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_14.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_14.metric_time__week AS metric_time__week - , subq_14.metric_time__month AS metric_time__month - , subq_14.metric_time__quarter AS metric_time__quarter - , subq_14.metric_time__year AS metric_time__year - , subq_14.metric_time__extract_year AS metric_time__extract_year - , subq_14.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_14.metric_time__extract_month AS metric_time__extract_month - , subq_14.metric_time__extract_day AS metric_time__extract_day - , subq_14.metric_time__extract_dow AS metric_time__extract_dow - , subq_14.metric_time__extract_doy AS metric_time__extract_doy - , subq_15.metric_time__day AS metric_time__day - , subq_14.listing AS listing - , subq_14.guest AS guest - , subq_14.host AS host - , subq_14.booking__listing AS booking__listing - , subq_14.booking__guest AS booking__guest - , subq_14.booking__host AS booking__host - , subq_14.is_instant AS is_instant - , subq_14.booking__is_instant AS booking__is_instant - , subq_14.bookings AS bookings - , subq_14.instant_bookings AS instant_bookings - , subq_14.booking_value AS booking_value - , subq_14.max_booking_value AS max_booking_value - , subq_14.min_booking_value AS min_booking_value - , subq_14.bookers AS bookers - , subq_14.average_booking_value AS average_booking_value - , subq_14.referred_bookings AS referred_bookings - , subq_14.median_booking_value AS median_booking_value - , subq_14.booking_value_p99 AS booking_value_p99 - , subq_14.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_14.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_14.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_15.ds__day AS ds__day + , subq_15.ds__week AS ds__week + , subq_15.ds__month AS ds__month + , subq_15.ds__quarter AS ds__quarter + , subq_15.ds__year AS ds__year + , subq_15.ds__extract_year AS ds__extract_year + , subq_15.ds__extract_quarter AS ds__extract_quarter + , subq_15.ds__extract_month AS ds__extract_month + , subq_15.ds__extract_day AS ds__extract_day + , subq_15.ds__extract_dow AS ds__extract_dow + , subq_15.ds__extract_doy AS ds__extract_doy + , subq_15.ds_partitioned__day AS ds_partitioned__day + , subq_15.ds_partitioned__week AS ds_partitioned__week + , subq_15.ds_partitioned__month AS ds_partitioned__month + , subq_15.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_15.ds_partitioned__year AS ds_partitioned__year + , subq_15.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_15.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_15.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_15.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_15.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_15.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_15.paid_at__day AS paid_at__day + , subq_15.paid_at__week AS paid_at__week + , subq_15.paid_at__month AS paid_at__month + , subq_15.paid_at__quarter AS paid_at__quarter + , subq_15.paid_at__year AS paid_at__year + , subq_15.paid_at__extract_year AS paid_at__extract_year + , subq_15.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_15.paid_at__extract_month AS paid_at__extract_month + , subq_15.paid_at__extract_day AS paid_at__extract_day + , subq_15.paid_at__extract_dow AS paid_at__extract_dow + , subq_15.paid_at__extract_doy AS paid_at__extract_doy + , subq_15.booking__ds__day AS booking__ds__day + , subq_15.booking__ds__week AS booking__ds__week + , subq_15.booking__ds__month AS booking__ds__month + , subq_15.booking__ds__quarter AS booking__ds__quarter + , subq_15.booking__ds__year AS booking__ds__year + , subq_15.booking__ds__extract_year AS booking__ds__extract_year + , subq_15.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_15.booking__ds__extract_month AS booking__ds__extract_month + , subq_15.booking__ds__extract_day AS booking__ds__extract_day + , subq_15.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_15.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_15.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_15.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_15.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_15.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_15.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_15.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_15.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_15.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_15.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_15.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_15.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_15.booking__paid_at__day AS booking__paid_at__day + , subq_15.booking__paid_at__week AS booking__paid_at__week + , subq_15.booking__paid_at__month AS booking__paid_at__month + , subq_15.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_15.booking__paid_at__year AS booking__paid_at__year + , subq_15.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_15.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_15.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_15.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_15.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_15.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_15.metric_time__week AS metric_time__week + , subq_15.metric_time__month AS metric_time__month + , subq_15.metric_time__quarter AS metric_time__quarter + , subq_15.metric_time__year AS metric_time__year + , subq_15.metric_time__extract_year AS metric_time__extract_year + , subq_15.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_15.metric_time__extract_month AS metric_time__extract_month + , subq_15.metric_time__extract_day AS metric_time__extract_day + , subq_15.metric_time__extract_dow AS metric_time__extract_dow + , subq_15.metric_time__extract_doy AS metric_time__extract_doy + , subq_18.metric_time__day AS metric_time__day + , subq_15.listing AS listing + , subq_15.guest AS guest + , subq_15.host AS host + , subq_15.booking__listing AS booking__listing + , subq_15.booking__guest AS booking__guest + , subq_15.booking__host AS booking__host + , subq_15.is_instant AS is_instant + , subq_15.booking__is_instant AS booking__is_instant + , subq_15.bookings AS bookings + , subq_15.instant_bookings AS instant_bookings + , subq_15.booking_value AS booking_value + , subq_15.max_booking_value AS max_booking_value + , subq_15.min_booking_value AS min_booking_value + , subq_15.bookers AS bookers + , subq_15.average_booking_value AS average_booking_value + , subq_15.referred_bookings AS referred_bookings + , subq_15.median_booking_value AS median_booking_value + , subq_15.booking_value_p99 AS booking_value_p99 + , subq_15.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_15.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_15.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_16.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_16 - ) subq_15 + subq_17.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_16.ds__day AS metric_time__day + , subq_16.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_16 + ) subq_17 + ) subq_18 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_13.ds__day - , subq_13.ds__week - , subq_13.ds__month - , subq_13.ds__quarter - , subq_13.ds__year - , subq_13.ds__extract_year - , subq_13.ds__extract_quarter - , subq_13.ds__extract_month - , subq_13.ds__extract_day - , subq_13.ds__extract_dow - , subq_13.ds__extract_doy - , subq_13.ds_partitioned__day - , subq_13.ds_partitioned__week - , subq_13.ds_partitioned__month - , subq_13.ds_partitioned__quarter - , subq_13.ds_partitioned__year - , subq_13.ds_partitioned__extract_year - , subq_13.ds_partitioned__extract_quarter - , subq_13.ds_partitioned__extract_month - , subq_13.ds_partitioned__extract_day - , subq_13.ds_partitioned__extract_dow - , subq_13.ds_partitioned__extract_doy - , subq_13.paid_at__day - , subq_13.paid_at__week - , subq_13.paid_at__month - , subq_13.paid_at__quarter - , subq_13.paid_at__year - , subq_13.paid_at__extract_year - , subq_13.paid_at__extract_quarter - , subq_13.paid_at__extract_month - , subq_13.paid_at__extract_day - , subq_13.paid_at__extract_dow - , subq_13.paid_at__extract_doy - , subq_13.booking__ds__day - , subq_13.booking__ds__week - , subq_13.booking__ds__month - , subq_13.booking__ds__quarter - , subq_13.booking__ds__year - , subq_13.booking__ds__extract_year - , subq_13.booking__ds__extract_quarter - , subq_13.booking__ds__extract_month - , subq_13.booking__ds__extract_day - , subq_13.booking__ds__extract_dow - , subq_13.booking__ds__extract_doy - , subq_13.booking__ds_partitioned__day - , subq_13.booking__ds_partitioned__week - , subq_13.booking__ds_partitioned__month - , subq_13.booking__ds_partitioned__quarter - , subq_13.booking__ds_partitioned__year - , subq_13.booking__ds_partitioned__extract_year - , subq_13.booking__ds_partitioned__extract_quarter - , subq_13.booking__ds_partitioned__extract_month - , subq_13.booking__ds_partitioned__extract_day - , subq_13.booking__ds_partitioned__extract_dow - , subq_13.booking__ds_partitioned__extract_doy - , subq_13.booking__paid_at__day - , subq_13.booking__paid_at__week - , subq_13.booking__paid_at__month - , subq_13.booking__paid_at__quarter - , subq_13.booking__paid_at__year - , subq_13.booking__paid_at__extract_year - , subq_13.booking__paid_at__extract_quarter - , subq_13.booking__paid_at__extract_month - , subq_13.booking__paid_at__extract_day - , subq_13.booking__paid_at__extract_dow - , subq_13.booking__paid_at__extract_doy - , subq_13.ds__day AS metric_time__day - , subq_13.ds__week AS metric_time__week - , subq_13.ds__month AS metric_time__month - , subq_13.ds__quarter AS metric_time__quarter - , subq_13.ds__year AS metric_time__year - , subq_13.ds__extract_year AS metric_time__extract_year - , subq_13.ds__extract_quarter AS metric_time__extract_quarter - , subq_13.ds__extract_month AS metric_time__extract_month - , subq_13.ds__extract_day AS metric_time__extract_day - , subq_13.ds__extract_dow AS metric_time__extract_dow - , subq_13.ds__extract_doy AS metric_time__extract_doy - , subq_13.listing - , subq_13.guest - , subq_13.host - , subq_13.booking__listing - , subq_13.booking__guest - , subq_13.booking__host - , subq_13.is_instant - , subq_13.booking__is_instant - , subq_13.bookings - , subq_13.instant_bookings - , subq_13.booking_value - , subq_13.max_booking_value - , subq_13.min_booking_value - , subq_13.bookers - , subq_13.average_booking_value - , subq_13.referred_bookings - , subq_13.median_booking_value - , subq_13.booking_value_p99 - , subq_13.discrete_booking_value_p99 - , subq_13.approximate_continuous_booking_value_p99 - , subq_13.approximate_discrete_booking_value_p99 + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -1133,86 +1199,86 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 - ) subq_14 + ) subq_14 + ) subq_15 ON - subq_15.metric_time__day - INTERVAL 14 day = subq_14.metric_time__day - ) subq_17 + subq_18.metric_time__day - INTERVAL 14 day = subq_15.metric_time__day + ) subq_19 LEFT OUTER JOIN ( -- Pass Only Elements: ['country_latest', 'listing'] SELECT - subq_19.listing - , subq_19.country_latest + subq_21.listing + , subq_21.country_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_18.ds__day - , subq_18.ds__week - , subq_18.ds__month - , subq_18.ds__quarter - , subq_18.ds__year - , subq_18.ds__extract_year - , subq_18.ds__extract_quarter - , subq_18.ds__extract_month - , subq_18.ds__extract_day - , subq_18.ds__extract_dow - , subq_18.ds__extract_doy - , subq_18.created_at__day - , subq_18.created_at__week - , subq_18.created_at__month - , subq_18.created_at__quarter - , subq_18.created_at__year - , subq_18.created_at__extract_year - , subq_18.created_at__extract_quarter - , subq_18.created_at__extract_month - , subq_18.created_at__extract_day - , subq_18.created_at__extract_dow - , subq_18.created_at__extract_doy - , subq_18.listing__ds__day - , subq_18.listing__ds__week - , subq_18.listing__ds__month - , subq_18.listing__ds__quarter - , subq_18.listing__ds__year - , subq_18.listing__ds__extract_year - , subq_18.listing__ds__extract_quarter - , subq_18.listing__ds__extract_month - , subq_18.listing__ds__extract_day - , subq_18.listing__ds__extract_dow - , subq_18.listing__ds__extract_doy - , subq_18.listing__created_at__day - , subq_18.listing__created_at__week - , subq_18.listing__created_at__month - , subq_18.listing__created_at__quarter - , subq_18.listing__created_at__year - , subq_18.listing__created_at__extract_year - , subq_18.listing__created_at__extract_quarter - , subq_18.listing__created_at__extract_month - , subq_18.listing__created_at__extract_day - , subq_18.listing__created_at__extract_dow - , subq_18.listing__created_at__extract_doy - , subq_18.ds__day AS metric_time__day - , subq_18.ds__week AS metric_time__week - , subq_18.ds__month AS metric_time__month - , subq_18.ds__quarter AS metric_time__quarter - , subq_18.ds__year AS metric_time__year - , subq_18.ds__extract_year AS metric_time__extract_year - , subq_18.ds__extract_quarter AS metric_time__extract_quarter - , subq_18.ds__extract_month AS metric_time__extract_month - , subq_18.ds__extract_day AS metric_time__extract_day - , subq_18.ds__extract_dow AS metric_time__extract_dow - , subq_18.ds__extract_doy AS metric_time__extract_doy - , subq_18.listing - , subq_18.user - , subq_18.listing__user - , subq_18.country_latest - , subq_18.is_lux_latest - , subq_18.capacity_latest - , subq_18.listing__country_latest - , subq_18.listing__is_lux_latest - , subq_18.listing__capacity_latest - , subq_18.listings - , subq_18.largest_listing - , subq_18.smallest_listing + subq_20.ds__day + , subq_20.ds__week + , subq_20.ds__month + , subq_20.ds__quarter + , subq_20.ds__year + , subq_20.ds__extract_year + , subq_20.ds__extract_quarter + , subq_20.ds__extract_month + , subq_20.ds__extract_day + , subq_20.ds__extract_dow + , subq_20.ds__extract_doy + , subq_20.created_at__day + , subq_20.created_at__week + , subq_20.created_at__month + , subq_20.created_at__quarter + , subq_20.created_at__year + , subq_20.created_at__extract_year + , subq_20.created_at__extract_quarter + , subq_20.created_at__extract_month + , subq_20.created_at__extract_day + , subq_20.created_at__extract_dow + , subq_20.created_at__extract_doy + , subq_20.listing__ds__day + , subq_20.listing__ds__week + , subq_20.listing__ds__month + , subq_20.listing__ds__quarter + , subq_20.listing__ds__year + , subq_20.listing__ds__extract_year + , subq_20.listing__ds__extract_quarter + , subq_20.listing__ds__extract_month + , subq_20.listing__ds__extract_day + , subq_20.listing__ds__extract_dow + , subq_20.listing__ds__extract_doy + , subq_20.listing__created_at__day + , subq_20.listing__created_at__week + , subq_20.listing__created_at__month + , subq_20.listing__created_at__quarter + , subq_20.listing__created_at__year + , subq_20.listing__created_at__extract_year + , subq_20.listing__created_at__extract_quarter + , subq_20.listing__created_at__extract_month + , subq_20.listing__created_at__extract_day + , subq_20.listing__created_at__extract_dow + , subq_20.listing__created_at__extract_doy + , subq_20.ds__day AS metric_time__day + , subq_20.ds__week AS metric_time__week + , subq_20.ds__month AS metric_time__month + , subq_20.ds__quarter AS metric_time__quarter + , subq_20.ds__year AS metric_time__year + , subq_20.ds__extract_year AS metric_time__extract_year + , subq_20.ds__extract_quarter AS metric_time__extract_quarter + , subq_20.ds__extract_month AS metric_time__extract_month + , subq_20.ds__extract_day AS metric_time__extract_day + , subq_20.ds__extract_dow AS metric_time__extract_dow + , subq_20.ds__extract_doy AS metric_time__extract_doy + , subq_20.listing + , subq_20.user + , subq_20.listing__user + , subq_20.country_latest + , subq_20.is_lux_latest + , subq_20.capacity_latest + , subq_20.listing__country_latest + , subq_20.listing__is_lux_latest + , subq_20.listing__capacity_latest + , subq_20.listings + , subq_20.largest_listing + , subq_20.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -1273,30 +1339,30 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_18 - ) subq_19 - ) subq_20 + ) subq_20 + ) subq_21 + ) subq_22 ON - subq_17.listing = subq_20.listing - ) subq_21 + subq_19.listing = subq_22.listing + ) subq_23 WHERE booking__is_instant - ) subq_22 - ) subq_23 + ) subq_24 + ) subq_25 GROUP BY - subq_23.metric_time__day - , subq_23.listing__country_latest - ) subq_24 + subq_25.metric_time__day + , subq_25.listing__country_latest + ) subq_26 ON - subq_25.metric_time__day = subq_24.metric_time__day - ) subq_27 - ) subq_28 + subq_29.metric_time__day = subq_26.metric_time__day + ) subq_30 + ) subq_31 ON ( - subq_12.listing__country_latest = subq_28.listing__country_latest + subq_13.listing__country_latest = subq_31.listing__country_latest ) AND ( - subq_12.metric_time__day = subq_28.metric_time__day + subq_13.metric_time__day = subq_31.metric_time__day ) GROUP BY - COALESCE(subq_12.metric_time__day, subq_28.metric_time__day) - , COALESCE(subq_12.listing__country_latest, subq_28.listing__country_latest) -) subq_29 + COALESCE(subq_13.metric_time__day, subq_31.metric_time__day) + , COALESCE(subq_13.listing__country_latest, subq_31.listing__country_latest) +) subq_32 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 353a58c7d..e7595b986 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql @@ -14,10 +14,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_42.metric_time__day, subq_58.metric_time__day) AS metric_time__day - , COALESCE(subq_42.listing__country_latest, subq_58.listing__country_latest) AS listing__country_latest - , COALESCE(MAX(subq_42.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , COALESCE(MAX(subq_58.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_46.metric_time__day, subq_64.metric_time__day) AS metric_time__day + , COALESCE(subq_46.listing__country_latest, subq_64.listing__country_latest) AS listing__country_latest + , COALESCE(MAX(subq_46.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , COALESCE(MAX(subq_64.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -27,10 +27,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_40.ds AS metric_time__day - , subq_38.listing__country_latest AS listing__country_latest - , subq_38.bookings AS bookings - FROM ***************************.mf_time_spine subq_40 + time_spine_src_28006.ds 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 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -43,9 +43,9 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.country AS listing__country_latest - , subq_31.metric_time__day AS metric_time__day - , subq_31.booking__is_instant AS booking__is_instant - , subq_31.bookings AS bookings + , subq_34.metric_time__day AS metric_time__day + , subq_34.booking__is_instant AS booking__is_instant + , subq_34.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -55,21 +55,21 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_31 + ) subq_34 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_31.listing = listings_latest_src_28000.listing_id - ) subq_35 + subq_34.listing = listings_latest_src_28000.listing_id + ) subq_38 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_38 + ) subq_41 ON - subq_40.ds = subq_38.metric_time__day - ) subq_41 - ) subq_42 + time_spine_src_28006.ds = subq_41.metric_time__day + ) subq_45 + ) subq_46 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT @@ -79,10 +79,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_56.ds AS metric_time__day - , subq_54.listing__country_latest AS listing__country_latest - , subq_54.bookings AS bookings - FROM ***************************.mf_time_spine subq_56 + time_spine_src_28006.ds AS metric_time__day + , subq_59.listing__country_latest AS listing__country_latest + , subq_59.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -95,17 +95,17 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.country AS listing__country_latest - , subq_47.metric_time__day AS metric_time__day - , subq_47.booking__is_instant AS booking__is_instant - , subq_47.bookings AS bookings + , subq_52.metric_time__day AS metric_time__day + , subq_52.booking__is_instant AS booking__is_instant + , subq_52.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_46.ds AS metric_time__day - , subq_44.listing AS listing - , subq_44.booking__is_instant AS booking__is_instant - , subq_44.bookings AS bookings - FROM ***************************.mf_time_spine subq_46 + time_spine_src_28006.ds AS metric_time__day + , subq_48.listing AS listing + , subq_48.booking__is_instant AS booking__is_instant + , subq_48.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -115,31 +115,31 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_44 + ) subq_48 ON - subq_46.ds - INTERVAL 14 day = subq_44.metric_time__day - ) subq_47 + time_spine_src_28006.ds - INTERVAL 14 day = subq_48.metric_time__day + ) subq_52 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_51 + subq_52.listing = listings_latest_src_28000.listing_id + ) subq_56 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_54 + ) subq_59 ON - subq_56.ds = subq_54.metric_time__day - ) subq_57 - ) subq_58 + time_spine_src_28006.ds = subq_59.metric_time__day + ) subq_63 + ) subq_64 ON ( - subq_42.listing__country_latest = subq_58.listing__country_latest + subq_46.listing__country_latest = subq_64.listing__country_latest ) AND ( - subq_42.metric_time__day = subq_58.metric_time__day + subq_46.metric_time__day = subq_64.metric_time__day ) GROUP BY - COALESCE(subq_42.metric_time__day, subq_58.metric_time__day) - , COALESCE(subq_42.listing__country_latest, subq_58.listing__country_latest) -) subq_59 + COALESCE(subq_46.metric_time__day, subq_64.metric_time__day) + , COALESCE(subq_46.listing__country_latest, subq_64.listing__country_latest) +) subq_65 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql index aee6eca8d..b6444d888 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_23.metric_time__day - , subq_23.listing__country_latest + subq_24.metric_time__day + , subq_24.listing__country_latest , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_9.metric_time__day, subq_22.metric_time__day) AS metric_time__day - , COALESCE(subq_9.listing__country_latest, subq_22.listing__country_latest) AS listing__country_latest + COALESCE(subq_9.metric_time__day, subq_23.metric_time__day) AS metric_time__day + , COALESCE(subq_9.listing__country_latest, subq_23.listing__country_latest) AS listing__country_latest , MAX(subq_9.bookings) AS bookings - , MAX(subq_22.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_23.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -587,225 +587,225 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_21.metric_time__day - , subq_21.listing__country_latest - , subq_21.bookings AS bookings_2_weeks_ago + subq_22.metric_time__day + , subq_22.listing__country_latest + , subq_22.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_20.metric_time__day - , subq_20.listing__country_latest - , SUM(subq_20.bookings) AS bookings + subq_21.metric_time__day + , subq_21.listing__country_latest + , SUM(subq_21.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] SELECT - subq_19.metric_time__day - , subq_19.listing__country_latest - , subq_19.bookings + subq_20.metric_time__day + , subq_20.listing__country_latest + , subq_20.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_18.metric_time__day - , subq_18.ds__day - , subq_18.ds__week - , subq_18.ds__month - , subq_18.ds__quarter - , subq_18.ds__year - , subq_18.ds__extract_year - , subq_18.ds__extract_quarter - , subq_18.ds__extract_month - , subq_18.ds__extract_day - , subq_18.ds__extract_dow - , subq_18.ds__extract_doy - , subq_18.ds_partitioned__day - , subq_18.ds_partitioned__week - , subq_18.ds_partitioned__month - , subq_18.ds_partitioned__quarter - , subq_18.ds_partitioned__year - , subq_18.ds_partitioned__extract_year - , subq_18.ds_partitioned__extract_quarter - , subq_18.ds_partitioned__extract_month - , subq_18.ds_partitioned__extract_day - , subq_18.ds_partitioned__extract_dow - , subq_18.ds_partitioned__extract_doy - , subq_18.paid_at__day - , subq_18.paid_at__week - , subq_18.paid_at__month - , subq_18.paid_at__quarter - , subq_18.paid_at__year - , subq_18.paid_at__extract_year - , subq_18.paid_at__extract_quarter - , subq_18.paid_at__extract_month - , subq_18.paid_at__extract_day - , subq_18.paid_at__extract_dow - , subq_18.paid_at__extract_doy - , subq_18.booking__ds__day - , subq_18.booking__ds__week - , subq_18.booking__ds__month - , subq_18.booking__ds__quarter - , subq_18.booking__ds__year - , subq_18.booking__ds__extract_year - , subq_18.booking__ds__extract_quarter - , subq_18.booking__ds__extract_month - , subq_18.booking__ds__extract_day - , subq_18.booking__ds__extract_dow - , subq_18.booking__ds__extract_doy - , subq_18.booking__ds_partitioned__day - , subq_18.booking__ds_partitioned__week - , subq_18.booking__ds_partitioned__month - , subq_18.booking__ds_partitioned__quarter - , subq_18.booking__ds_partitioned__year - , subq_18.booking__ds_partitioned__extract_year - , subq_18.booking__ds_partitioned__extract_quarter - , subq_18.booking__ds_partitioned__extract_month - , subq_18.booking__ds_partitioned__extract_day - , subq_18.booking__ds_partitioned__extract_dow - , subq_18.booking__ds_partitioned__extract_doy - , subq_18.booking__paid_at__day - , subq_18.booking__paid_at__week - , subq_18.booking__paid_at__month - , subq_18.booking__paid_at__quarter - , subq_18.booking__paid_at__year - , subq_18.booking__paid_at__extract_year - , subq_18.booking__paid_at__extract_quarter - , subq_18.booking__paid_at__extract_month - , subq_18.booking__paid_at__extract_day - , subq_18.booking__paid_at__extract_dow - , subq_18.booking__paid_at__extract_doy - , subq_18.metric_time__week - , subq_18.metric_time__month - , subq_18.metric_time__quarter - , subq_18.metric_time__year - , subq_18.metric_time__extract_year - , subq_18.metric_time__extract_quarter - , subq_18.metric_time__extract_month - , subq_18.metric_time__extract_day - , subq_18.metric_time__extract_dow - , subq_18.metric_time__extract_doy - , subq_18.listing - , subq_18.guest - , subq_18.host - , subq_18.booking__listing - , subq_18.booking__guest - , subq_18.booking__host - , subq_18.is_instant - , subq_18.booking__is_instant - , subq_18.listing__country_latest - , subq_18.bookings - , subq_18.instant_bookings - , subq_18.booking_value - , subq_18.max_booking_value - , subq_18.min_booking_value - , subq_18.bookers - , subq_18.average_booking_value - , subq_18.referred_bookings - , subq_18.median_booking_value - , subq_18.booking_value_p99 - , subq_18.discrete_booking_value_p99 - , subq_18.approximate_continuous_booking_value_p99 - , subq_18.approximate_discrete_booking_value_p99 + subq_19.ds__day + , subq_19.ds__week + , subq_19.ds__month + , subq_19.ds__quarter + , subq_19.ds__year + , subq_19.ds__extract_year + , subq_19.ds__extract_quarter + , subq_19.ds__extract_month + , subq_19.ds__extract_day + , subq_19.ds__extract_dow + , subq_19.ds__extract_doy + , subq_19.ds_partitioned__day + , subq_19.ds_partitioned__week + , subq_19.ds_partitioned__month + , subq_19.ds_partitioned__quarter + , subq_19.ds_partitioned__year + , subq_19.ds_partitioned__extract_year + , subq_19.ds_partitioned__extract_quarter + , subq_19.ds_partitioned__extract_month + , subq_19.ds_partitioned__extract_day + , subq_19.ds_partitioned__extract_dow + , subq_19.ds_partitioned__extract_doy + , subq_19.paid_at__day + , subq_19.paid_at__week + , subq_19.paid_at__month + , subq_19.paid_at__quarter + , subq_19.paid_at__year + , subq_19.paid_at__extract_year + , subq_19.paid_at__extract_quarter + , subq_19.paid_at__extract_month + , subq_19.paid_at__extract_day + , subq_19.paid_at__extract_dow + , subq_19.paid_at__extract_doy + , subq_19.booking__ds__day + , subq_19.booking__ds__week + , subq_19.booking__ds__month + , subq_19.booking__ds__quarter + , subq_19.booking__ds__year + , subq_19.booking__ds__extract_year + , subq_19.booking__ds__extract_quarter + , subq_19.booking__ds__extract_month + , subq_19.booking__ds__extract_day + , subq_19.booking__ds__extract_dow + , subq_19.booking__ds__extract_doy + , subq_19.booking__ds_partitioned__day + , subq_19.booking__ds_partitioned__week + , subq_19.booking__ds_partitioned__month + , subq_19.booking__ds_partitioned__quarter + , subq_19.booking__ds_partitioned__year + , subq_19.booking__ds_partitioned__extract_year + , subq_19.booking__ds_partitioned__extract_quarter + , subq_19.booking__ds_partitioned__extract_month + , subq_19.booking__ds_partitioned__extract_day + , subq_19.booking__ds_partitioned__extract_dow + , subq_19.booking__ds_partitioned__extract_doy + , subq_19.booking__paid_at__day + , subq_19.booking__paid_at__week + , subq_19.booking__paid_at__month + , subq_19.booking__paid_at__quarter + , subq_19.booking__paid_at__year + , subq_19.booking__paid_at__extract_year + , subq_19.booking__paid_at__extract_quarter + , subq_19.booking__paid_at__extract_month + , subq_19.booking__paid_at__extract_day + , subq_19.booking__paid_at__extract_dow + , subq_19.booking__paid_at__extract_doy + , subq_19.metric_time__week + , subq_19.metric_time__month + , subq_19.metric_time__quarter + , subq_19.metric_time__year + , subq_19.metric_time__extract_year + , subq_19.metric_time__extract_quarter + , subq_19.metric_time__extract_month + , subq_19.metric_time__extract_day + , subq_19.metric_time__extract_dow + , subq_19.metric_time__extract_doy + , subq_19.metric_time__day + , subq_19.listing + , subq_19.guest + , subq_19.host + , subq_19.booking__listing + , subq_19.booking__guest + , subq_19.booking__host + , subq_19.is_instant + , subq_19.booking__is_instant + , subq_19.listing__country_latest + , subq_19.bookings + , subq_19.instant_bookings + , subq_19.booking_value + , subq_19.max_booking_value + , subq_19.min_booking_value + , subq_19.bookers + , subq_19.average_booking_value + , subq_19.referred_bookings + , subq_19.median_booking_value + , subq_19.booking_value_p99 + , subq_19.discrete_booking_value_p99 + , subq_19.approximate_continuous_booking_value_p99 + , subq_19.approximate_discrete_booking_value_p99 FROM ( -- Join Standard Outputs SELECT - subq_17.country_latest AS listing__country_latest - , subq_14.metric_time__day AS metric_time__day - , subq_14.ds__day AS ds__day - , subq_14.ds__week AS ds__week - , subq_14.ds__month AS ds__month - , subq_14.ds__quarter AS ds__quarter - , subq_14.ds__year AS ds__year - , subq_14.ds__extract_year AS ds__extract_year - , subq_14.ds__extract_quarter AS ds__extract_quarter - , subq_14.ds__extract_month AS ds__extract_month - , subq_14.ds__extract_day AS ds__extract_day - , subq_14.ds__extract_dow AS ds__extract_dow - , subq_14.ds__extract_doy AS ds__extract_doy - , subq_14.ds_partitioned__day AS ds_partitioned__day - , subq_14.ds_partitioned__week AS ds_partitioned__week - , subq_14.ds_partitioned__month AS ds_partitioned__month - , subq_14.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_14.ds_partitioned__year AS ds_partitioned__year - , subq_14.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_14.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_14.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_14.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_14.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_14.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_14.paid_at__day AS paid_at__day - , subq_14.paid_at__week AS paid_at__week - , subq_14.paid_at__month AS paid_at__month - , subq_14.paid_at__quarter AS paid_at__quarter - , subq_14.paid_at__year AS paid_at__year - , subq_14.paid_at__extract_year AS paid_at__extract_year - , subq_14.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_14.paid_at__extract_month AS paid_at__extract_month - , subq_14.paid_at__extract_day AS paid_at__extract_day - , subq_14.paid_at__extract_dow AS paid_at__extract_dow - , subq_14.paid_at__extract_doy AS paid_at__extract_doy - , subq_14.booking__ds__day AS booking__ds__day - , subq_14.booking__ds__week AS booking__ds__week - , subq_14.booking__ds__month AS booking__ds__month - , subq_14.booking__ds__quarter AS booking__ds__quarter - , subq_14.booking__ds__year AS booking__ds__year - , subq_14.booking__ds__extract_year AS booking__ds__extract_year - , subq_14.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_14.booking__ds__extract_month AS booking__ds__extract_month - , subq_14.booking__ds__extract_day AS booking__ds__extract_day - , subq_14.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_14.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_14.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_14.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_14.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_14.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_14.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_14.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_14.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_14.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_14.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_14.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_14.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_14.booking__paid_at__day AS booking__paid_at__day - , subq_14.booking__paid_at__week AS booking__paid_at__week - , subq_14.booking__paid_at__month AS booking__paid_at__month - , subq_14.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_14.booking__paid_at__year AS booking__paid_at__year - , subq_14.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_14.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_14.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_14.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_14.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_14.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_14.metric_time__week AS metric_time__week - , subq_14.metric_time__month AS metric_time__month - , subq_14.metric_time__quarter AS metric_time__quarter - , subq_14.metric_time__year AS metric_time__year - , subq_14.metric_time__extract_year AS metric_time__extract_year - , subq_14.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_14.metric_time__extract_month AS metric_time__extract_month - , subq_14.metric_time__extract_day AS metric_time__extract_day - , subq_14.metric_time__extract_dow AS metric_time__extract_dow - , subq_14.metric_time__extract_doy AS metric_time__extract_doy - , subq_14.listing AS listing - , subq_14.guest AS guest - , subq_14.host AS host - , subq_14.booking__listing AS booking__listing - , subq_14.booking__guest AS booking__guest - , subq_14.booking__host AS booking__host - , subq_14.is_instant AS is_instant - , subq_14.booking__is_instant AS booking__is_instant - , subq_14.bookings AS bookings - , subq_14.instant_bookings AS instant_bookings - , subq_14.booking_value AS booking_value - , subq_14.max_booking_value AS max_booking_value - , subq_14.min_booking_value AS min_booking_value - , subq_14.bookers AS bookers - , subq_14.average_booking_value AS average_booking_value - , subq_14.referred_bookings AS referred_bookings - , subq_14.median_booking_value AS median_booking_value - , subq_14.booking_value_p99 AS booking_value_p99 - , subq_14.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_14.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_14.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_18.country_latest AS listing__country_latest + , subq_15.ds__day AS ds__day + , subq_15.ds__week AS ds__week + , subq_15.ds__month AS ds__month + , subq_15.ds__quarter AS ds__quarter + , subq_15.ds__year AS ds__year + , subq_15.ds__extract_year AS ds__extract_year + , subq_15.ds__extract_quarter AS ds__extract_quarter + , subq_15.ds__extract_month AS ds__extract_month + , subq_15.ds__extract_day AS ds__extract_day + , subq_15.ds__extract_dow AS ds__extract_dow + , subq_15.ds__extract_doy AS ds__extract_doy + , subq_15.ds_partitioned__day AS ds_partitioned__day + , subq_15.ds_partitioned__week AS ds_partitioned__week + , subq_15.ds_partitioned__month AS ds_partitioned__month + , subq_15.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_15.ds_partitioned__year AS ds_partitioned__year + , subq_15.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_15.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_15.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_15.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_15.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_15.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_15.paid_at__day AS paid_at__day + , subq_15.paid_at__week AS paid_at__week + , subq_15.paid_at__month AS paid_at__month + , subq_15.paid_at__quarter AS paid_at__quarter + , subq_15.paid_at__year AS paid_at__year + , subq_15.paid_at__extract_year AS paid_at__extract_year + , subq_15.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_15.paid_at__extract_month AS paid_at__extract_month + , subq_15.paid_at__extract_day AS paid_at__extract_day + , subq_15.paid_at__extract_dow AS paid_at__extract_dow + , subq_15.paid_at__extract_doy AS paid_at__extract_doy + , subq_15.booking__ds__day AS booking__ds__day + , subq_15.booking__ds__week AS booking__ds__week + , subq_15.booking__ds__month AS booking__ds__month + , subq_15.booking__ds__quarter AS booking__ds__quarter + , subq_15.booking__ds__year AS booking__ds__year + , subq_15.booking__ds__extract_year AS booking__ds__extract_year + , subq_15.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_15.booking__ds__extract_month AS booking__ds__extract_month + , subq_15.booking__ds__extract_day AS booking__ds__extract_day + , subq_15.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_15.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_15.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_15.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_15.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_15.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_15.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_15.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_15.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_15.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_15.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_15.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_15.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_15.booking__paid_at__day AS booking__paid_at__day + , subq_15.booking__paid_at__week AS booking__paid_at__week + , subq_15.booking__paid_at__month AS booking__paid_at__month + , subq_15.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_15.booking__paid_at__year AS booking__paid_at__year + , subq_15.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_15.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_15.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_15.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_15.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_15.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_15.metric_time__week AS metric_time__week + , subq_15.metric_time__month AS metric_time__month + , subq_15.metric_time__quarter AS metric_time__quarter + , subq_15.metric_time__year AS metric_time__year + , subq_15.metric_time__extract_year AS metric_time__extract_year + , subq_15.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_15.metric_time__extract_month AS metric_time__extract_month + , subq_15.metric_time__extract_day AS metric_time__extract_day + , subq_15.metric_time__extract_dow AS metric_time__extract_dow + , subq_15.metric_time__extract_doy AS metric_time__extract_doy + , subq_15.metric_time__day AS metric_time__day + , subq_15.listing AS listing + , subq_15.guest AS guest + , subq_15.host AS host + , subq_15.booking__listing AS booking__listing + , subq_15.booking__guest AS booking__guest + , subq_15.booking__host AS booking__host + , subq_15.is_instant AS is_instant + , subq_15.booking__is_instant AS booking__is_instant + , subq_15.bookings AS bookings + , subq_15.instant_bookings AS instant_bookings + , subq_15.booking_value AS booking_value + , subq_15.max_booking_value AS max_booking_value + , subq_15.min_booking_value AS min_booking_value + , subq_15.bookers AS bookers + , subq_15.average_booking_value AS average_booking_value + , subq_15.referred_bookings AS referred_bookings + , subq_15.median_booking_value AS median_booking_value + , subq_15.booking_value_p99 AS booking_value_p99 + , subq_15.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_15.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_15.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -885,7 +885,7 @@ FROM ( , subq_11.metric_time__extract_day AS metric_time__extract_day , subq_11.metric_time__extract_dow AS metric_time__extract_dow , subq_11.metric_time__extract_doy AS metric_time__extract_doy - , subq_12.metric_time__day AS metric_time__day + , subq_14.metric_time__day AS metric_time__day , subq_11.listing AS listing , subq_11.guest AS guest , subq_11.host AS host @@ -908,11 +908,33 @@ FROM ( , subq_11.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 , subq_11.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day', 'metric_time__day'] SELECT - subq_13.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_13 - ) subq_12 + subq_13.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_12.ds__day AS metric_time__day + , subq_12.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_12 + ) subq_13 + ) subq_14 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -1109,83 +1131,83 @@ FROM ( ) subq_10 ) subq_11 ON - subq_12.metric_time__day - INTERVAL 14 day = subq_11.metric_time__day - ) subq_14 + subq_14.metric_time__day - INTERVAL 14 day = subq_11.metric_time__day + ) subq_15 LEFT OUTER JOIN ( -- Pass Only Elements: ['country_latest', 'listing'] SELECT - subq_16.listing - , subq_16.country_latest + subq_17.listing + , subq_17.country_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_15.ds__day - , subq_15.ds__week - , subq_15.ds__month - , subq_15.ds__quarter - , subq_15.ds__year - , subq_15.ds__extract_year - , subq_15.ds__extract_quarter - , subq_15.ds__extract_month - , subq_15.ds__extract_day - , subq_15.ds__extract_dow - , subq_15.ds__extract_doy - , subq_15.created_at__day - , subq_15.created_at__week - , subq_15.created_at__month - , subq_15.created_at__quarter - , subq_15.created_at__year - , subq_15.created_at__extract_year - , subq_15.created_at__extract_quarter - , subq_15.created_at__extract_month - , subq_15.created_at__extract_day - , subq_15.created_at__extract_dow - , subq_15.created_at__extract_doy - , subq_15.listing__ds__day - , subq_15.listing__ds__week - , subq_15.listing__ds__month - , subq_15.listing__ds__quarter - , subq_15.listing__ds__year - , subq_15.listing__ds__extract_year - , subq_15.listing__ds__extract_quarter - , subq_15.listing__ds__extract_month - , subq_15.listing__ds__extract_day - , subq_15.listing__ds__extract_dow - , subq_15.listing__ds__extract_doy - , subq_15.listing__created_at__day - , subq_15.listing__created_at__week - , subq_15.listing__created_at__month - , subq_15.listing__created_at__quarter - , subq_15.listing__created_at__year - , subq_15.listing__created_at__extract_year - , subq_15.listing__created_at__extract_quarter - , subq_15.listing__created_at__extract_month - , subq_15.listing__created_at__extract_day - , subq_15.listing__created_at__extract_dow - , subq_15.listing__created_at__extract_doy - , subq_15.ds__day AS metric_time__day - , subq_15.ds__week AS metric_time__week - , subq_15.ds__month AS metric_time__month - , subq_15.ds__quarter AS metric_time__quarter - , subq_15.ds__year AS metric_time__year - , subq_15.ds__extract_year AS metric_time__extract_year - , subq_15.ds__extract_quarter AS metric_time__extract_quarter - , subq_15.ds__extract_month AS metric_time__extract_month - , subq_15.ds__extract_day AS metric_time__extract_day - , subq_15.ds__extract_dow AS metric_time__extract_dow - , subq_15.ds__extract_doy AS metric_time__extract_doy - , subq_15.listing - , subq_15.user - , subq_15.listing__user - , subq_15.country_latest - , subq_15.is_lux_latest - , subq_15.capacity_latest - , subq_15.listing__country_latest - , subq_15.listing__is_lux_latest - , subq_15.listing__capacity_latest - , subq_15.listings - , subq_15.largest_listing - , subq_15.smallest_listing + subq_16.ds__day + , subq_16.ds__week + , subq_16.ds__month + , subq_16.ds__quarter + , subq_16.ds__year + , subq_16.ds__extract_year + , subq_16.ds__extract_quarter + , subq_16.ds__extract_month + , subq_16.ds__extract_day + , subq_16.ds__extract_dow + , subq_16.ds__extract_doy + , subq_16.created_at__day + , subq_16.created_at__week + , subq_16.created_at__month + , subq_16.created_at__quarter + , subq_16.created_at__year + , subq_16.created_at__extract_year + , subq_16.created_at__extract_quarter + , subq_16.created_at__extract_month + , subq_16.created_at__extract_day + , subq_16.created_at__extract_dow + , subq_16.created_at__extract_doy + , subq_16.listing__ds__day + , subq_16.listing__ds__week + , subq_16.listing__ds__month + , subq_16.listing__ds__quarter + , subq_16.listing__ds__year + , subq_16.listing__ds__extract_year + , subq_16.listing__ds__extract_quarter + , subq_16.listing__ds__extract_month + , subq_16.listing__ds__extract_day + , subq_16.listing__ds__extract_dow + , subq_16.listing__ds__extract_doy + , subq_16.listing__created_at__day + , subq_16.listing__created_at__week + , subq_16.listing__created_at__month + , subq_16.listing__created_at__quarter + , subq_16.listing__created_at__year + , subq_16.listing__created_at__extract_year + , subq_16.listing__created_at__extract_quarter + , subq_16.listing__created_at__extract_month + , subq_16.listing__created_at__extract_day + , subq_16.listing__created_at__extract_dow + , subq_16.listing__created_at__extract_doy + , subq_16.ds__day AS metric_time__day + , subq_16.ds__week AS metric_time__week + , subq_16.ds__month AS metric_time__month + , subq_16.ds__quarter AS metric_time__quarter + , subq_16.ds__year AS metric_time__year + , subq_16.ds__extract_year AS metric_time__extract_year + , subq_16.ds__extract_quarter AS metric_time__extract_quarter + , subq_16.ds__extract_month AS metric_time__extract_month + , subq_16.ds__extract_day AS metric_time__extract_day + , subq_16.ds__extract_dow AS metric_time__extract_dow + , subq_16.ds__extract_doy AS metric_time__extract_doy + , subq_16.listing + , subq_16.user + , subq_16.listing__user + , subq_16.country_latest + , subq_16.is_lux_latest + , subq_16.capacity_latest + , subq_16.listing__country_latest + , subq_16.listing__is_lux_latest + , subq_16.listing__capacity_latest + , subq_16.listings + , subq_16.largest_listing + , subq_16.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -1246,27 +1268,27 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_15 - ) subq_16 - ) subq_17 + ) subq_16 + ) subq_17 + ) subq_18 ON - subq_14.listing = subq_17.listing - ) subq_18 + subq_15.listing = subq_18.listing + ) subq_19 WHERE booking__is_instant - ) subq_19 - ) subq_20 + ) subq_20 + ) subq_21 GROUP BY - subq_20.metric_time__day - , subq_20.listing__country_latest - ) subq_21 - ) subq_22 + subq_21.metric_time__day + , subq_21.listing__country_latest + ) subq_22 + ) subq_23 ON ( - subq_9.listing__country_latest = subq_22.listing__country_latest + subq_9.listing__country_latest = subq_23.listing__country_latest ) AND ( - subq_9.metric_time__day = subq_22.metric_time__day + subq_9.metric_time__day = subq_23.metric_time__day ) GROUP BY - COALESCE(subq_9.metric_time__day, subq_22.metric_time__day) - , COALESCE(subq_9.listing__country_latest, subq_22.listing__country_latest) -) subq_23 + COALESCE(subq_9.metric_time__day, subq_23.metric_time__day) + , COALESCE(subq_9.listing__country_latest, subq_23.listing__country_latest) +) subq_24 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql index e8368747a..f9105f81a 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql @@ -14,10 +14,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_33.metric_time__day, subq_46.metric_time__day) AS metric_time__day - , COALESCE(subq_33.listing__country_latest, subq_46.listing__country_latest) AS listing__country_latest - , MAX(subq_33.bookings) AS bookings - , MAX(subq_46.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_34.metric_time__day, subq_48.metric_time__day) AS metric_time__day + , COALESCE(subq_34.listing__country_latest, subq_48.listing__country_latest) AS listing__country_latest + , MAX(subq_34.bookings) AS bookings + , MAX(subq_48.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -31,9 +31,9 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.country AS listing__country_latest - , subq_25.metric_time__day AS metric_time__day - , subq_25.booking__is_instant AS booking__is_instant - , subq_25.bookings AS bookings + , subq_26.metric_time__day AS metric_time__day + , subq_26.booking__is_instant AS booking__is_instant + , subq_26.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -43,17 +43,17 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_25 + ) subq_26 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_25.listing = listings_latest_src_28000.listing_id - ) subq_29 + subq_26.listing = listings_latest_src_28000.listing_id + ) subq_30 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_33 + ) subq_34 FULL OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -67,17 +67,17 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.country AS listing__country_latest - , subq_38.metric_time__day AS metric_time__day - , subq_38.booking__is_instant AS booking__is_instant - , subq_38.bookings AS bookings + , subq_40.metric_time__day AS metric_time__day + , subq_40.booking__is_instant AS booking__is_instant + , subq_40.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_37.ds AS metric_time__day - , subq_35.listing AS listing - , subq_35.booking__is_instant AS booking__is_instant - , subq_35.bookings AS bookings - FROM ***************************.mf_time_spine subq_37 + time_spine_src_28006.ds AS metric_time__day + , subq_36.listing AS listing + , subq_36.booking__is_instant AS booking__is_instant + , subq_36.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -87,27 +87,27 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_35 + ) subq_36 ON - subq_37.ds - INTERVAL 14 day = subq_35.metric_time__day - ) subq_38 + time_spine_src_28006.ds - INTERVAL 14 day = subq_36.metric_time__day + ) subq_40 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_38.listing = listings_latest_src_28000.listing_id - ) subq_42 + subq_40.listing = listings_latest_src_28000.listing_id + ) subq_44 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_46 + ) subq_48 ON ( - subq_33.listing__country_latest = subq_46.listing__country_latest + subq_34.listing__country_latest = subq_48.listing__country_latest ) AND ( - subq_33.metric_time__day = subq_46.metric_time__day + subq_34.metric_time__day = subq_48.metric_time__day ) GROUP BY - COALESCE(subq_33.metric_time__day, subq_46.metric_time__day) - , COALESCE(subq_33.listing__country_latest, subq_46.listing__country_latest) -) subq_47 + COALESCE(subq_34.metric_time__day, subq_48.metric_time__day) + , COALESCE(subq_34.listing__country_latest, subq_48.listing__country_latest) +) subq_49 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index 6a063e32f..7d639689d 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.booking__is_instant - , subq_8.bookings AS bookings_join_to_time_spine + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings AS bookings_join_to_time_spine FROM ( -- Constrain Output with WHERE SELECT - subq_7.metric_time__day - , subq_7.booking__is_instant - , subq_7.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_7.metric_time__day AS metric_time__day , subq_4.booking__is_instant AS booking__is_instant , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -345,7 +367,7 @@ FROM ( , subq_3.booking__is_instant ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_7.metric_time__day = subq_4.metric_time__day + ) subq_8 WHERE booking__is_instant -) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index c5ff38a66..8ca9901da 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql @@ -15,10 +15,10 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_15.ds AS metric_time__day - , subq_13.booking__is_instant AS booking__is_instant - , subq_13.bookings AS bookings - FROM ***************************.mf_time_spine subq_15 + time_spine_src_28006.ds AS metric_time__day + , subq_14.booking__is_instant AS booking__is_instant + , subq_14.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -35,13 +35,13 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_14 ON - subq_15.ds = subq_13.metric_time__day -) subq_16 + time_spine_src_28006.ds = subq_14.metric_time__day +) subq_18 WHERE booking__is_instant diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index 82c85e9bd..de9b4ae67 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.booking__is_instant - , subq_8.bookings AS instant_bookings_with_measure_filter + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings AS instant_bookings_with_measure_filter FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.booking__is_instant AS booking__is_instant , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__day + , subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + WHERE metric_time__day > '2020-01-01' ) subq_7 - WHERE metric_time__day > '2020-01-01' - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -345,5 +368,5 @@ FROM ( , subq_3.booking__is_instant ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index 12b8e9746..ad75aec55 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.booking__is_instant AS booking__is_instant - , subq_13.bookings AS instant_bookings_with_measure_filter + subq_18.metric_time__day AS metric_time__day + , subq_14.booking__is_instant AS booking__is_instant + , subq_14.bookings AS instant_bookings_with_measure_filter FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 WHERE metric_time__day > '2020-01-01' -) subq_14 +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -41,11 +43,11 @@ LEFT OUTER JOIN ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((booking__is_instant) AND (listing IS NOT NULL)) AND (metric_time__day > '2020-01-01') GROUP BY metric_time__day , booking__is_instant -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.metric_time__day diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 2ce1521c9..23f94edf6 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_10.metric_time__day + , COALESCE(subq_10.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_7.metric_time__day - , subq_7.bookings + subq_9.metric_time__day + , subq_9.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - WHERE subq_6.ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_5 + subq_7.metric_time__day + FROM ( + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + SELECT + subq_6.ds__day + , subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' + ) subq_7 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -338,7 +366,7 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 - WHERE subq_7.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day + ) subq_9 + WHERE subq_9.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_10 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index 6e1385158..70c711ace 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql @@ -12,15 +12,18 @@ FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.bookings AS bookings + subq_19.metric_time__day AS metric_time__day + , subq_15.bookings AS bookings FROM ( -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + -- Pass Only Elements: ['metric_time__day',] SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_14 + ) subq_19 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -36,11 +39,11 @@ FROM ( , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_12 + ) subq_14 GROUP BY metric_time__day - ) subq_13 + ) subq_15 ON - subq_14.metric_time__day = subq_13.metric_time__day - WHERE subq_14.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_17 + subq_19.metric_time__day = subq_15.metric_time__day + WHERE subq_19.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_21 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql index a916df15a..8a3e5a834 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings AS bookings_join_to_time_spine + subq_7.metric_time__day + , subq_7.bookings AS bookings_join_to_time_spine FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_4.ds__day AS metric_time__day + , subq_4.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +249,5 @@ FROM ( subq_2.metric_time__day ) subq_3 ON - subq_4.metric_time__day = subq_3.metric_time__day -) subq_6 + subq_6.metric_time__day = subq_3.metric_time__day +) subq_7 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql index c8ecb775a..7be71a09b 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ds AS metric_time__day - , subq_10.bookings AS bookings_join_to_time_spine -FROM ***************************.mf_time_spine subq_12 + time_spine_src_28006.ds AS metric_time__day + , subq_11.bookings AS bookings_join_to_time_spine +FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -21,9 +21,9 @@ LEFT OUTER JOIN ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__day -) subq_10 +) subq_11 ON - subq_12.ds = subq_10.metric_time__day + time_spine_src_28006.ds = subq_11.metric_time__day diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql index 67dfb9f89..418ae5b38 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 + subq_8.metric_time__day + , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_7.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -332,5 +354,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_7 + subq_7.metric_time__day = subq_4.metric_time__day +) subq_8 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index 8a474a706..58b71e0dc 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql @@ -11,9 +11,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_14.ds AS metric_time__day - , subq_12.bookings AS bookings - FROM ***************************.mf_time_spine subq_14 + time_spine_src_28006.ds AS metric_time__day + , subq_13.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -29,11 +29,11 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_12 + ) subq_13 ON - subq_14.ds = subq_12.metric_time__day -) subq_15 + time_spine_src_28006.ds = subq_13.metric_time__day +) subq_17 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index 37c2eb64f..3b4a44407 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.booking__is_instant - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_9.metric_time__day + , subq_9.booking__is_instant + , COALESCE(subq_9.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Constrain Output with WHERE SELECT - subq_7.metric_time__day - , subq_7.booking__is_instant - , subq_7.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_7.metric_time__day AS metric_time__day , subq_4.booking__is_instant AS booking__is_instant , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month + , EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day + , EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow + , EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy + , time_spine_src_28006.martian_day AS ds__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_5 + ) subq_6 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -343,7 +365,7 @@ FROM ( , subq_3.booking__is_instant ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_7.metric_time__day = subq_4.metric_time__day + ) subq_8 WHERE booking__is_instant -) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index 6a3d97a37..473dd7f25 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql @@ -18,10 +18,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_15.ds AS metric_time__day - , subq_13.booking__is_instant AS booking__is_instant - , subq_13.bookings AS bookings - FROM ***************************.mf_time_spine subq_15 + time_spine_src_28006.ds AS metric_time__day + , subq_14.booking__is_instant AS booking__is_instant + , subq_14.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -38,14 +38,14 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_14 ON - subq_15.ds = subq_13.metric_time__day - ) subq_16 + time_spine_src_28006.ds = subq_14.metric_time__day + ) subq_18 WHERE booking__is_instant -) subq_17 +) subq_19