From d5d45625a59829e3bee17d377a7967dd96441a78 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Fri, 22 Nov 2024 22:45:44 -0800 Subject: [PATCH] Update SQL engine snapshots --- ...timespine_and_fill_nulls_with_0__plan0.sql | 456 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 66 +- ...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.sql | 460 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...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.sql | 460 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...timespine_and_fill_nulls_with_0__plan0.sql | 460 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ..._metric_with_non_default_grains__plan0.sql | 78 +- ...th_non_default_grains__plan0_optimized.sql | 30 +- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_grouped_by_custom_grain__plan0.sql | 42 +- ...ouped_by_custom_grain__plan0_optimized.sql | 24 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 4 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._metric_with_custom_granularity__plan0.sql | 62 +- ...th_custom_granularity__plan0_optimized.sql | 16 +- ...nularity_filter_not_in_group_by__plan0.sql | 262 ++-- ...ilter_not_in_group_by__plan0_optimized.sql | 20 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 6 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._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 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 6 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._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 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 6 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._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 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 6 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._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 +- ..._metric_grouped_by_custom_grain__plan0.sql | 44 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 376 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 374 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ...ity_joined_to_non_default_grain__plan0.sql | 2 +- ..._to_non_default_grain__plan0_optimized.sql | 6 +- ..._custom_granularity_metric_time__plan0.sql | 2 +- ...anularity_metric_time__plan0_optimized.sql | 2 +- ..._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 +- ...set_metric_with_time_constraint__plan0.sql | 256 ++-- ..._with_time_constraint__plan0_optimized.sql | 22 +- ...nth_dimension_and_offset_window__plan0.sql | 56 +- ...ion_and_offset_window__plan0_optimized.sql | 12 +- ...ved_metric_with_offset_to_grain__plan0.sql | 64 +- ..._with_offset_to_grain__plan0_optimized.sql | 26 +- ...offset_to_grain_and_granularity__plan0.sql | 72 +- ...grain_and_granularity__plan0_optimized.sql | 28 +- ...rived_metric_with_offset_window__plan0.sql | 64 +- ...ic_with_offset_window__plan0_optimized.sql | 26 +- ...h_offset_window_and_granularity__plan0.sql | 70 +- ...indow_and_granularity__plan0_optimized.sql | 26 +- ...fset_window_and_offset_to_grain__plan0.sql | 514 ++++---- ...w_and_offset_to_grain__plan0_optimized.sql | 34 +- ...offset_to_grain_and_granularity__plan0.sql | 526 ++++---- ...grain_and_granularity__plan0_optimized.sql | 36 +- ...h_offset_window_and_time_filter__plan0.sql | 262 ++-- ...indow_and_time_filter__plan0_optimized.sql | 28 +- ...erived_offset_cumulative_metric__plan0.sql | 56 +- ...set_cumulative_metric__plan0_optimized.sql | 20 +- ...offset_metric_with_agg_time_dim__plan0.sql | 284 +++-- ...ric_with_agg_time_dim__plan0_optimized.sql | 20 +- ...et_metric_with_one_input_metric__plan0.sql | 56 +- ...with_one_input_metric__plan0_optimized.sql | 12 +- ...d_where_constraint_not_selected__plan0.sql | 122 +- ...nstraint_not_selected__plan0_optimized.sql | 30 +- ...h_offset_multiple_input_metrics__plan0.sql | 270 ++-- ...ultiple_input_metrics__plan0_optimized.sql | 28 +- .../BigQuery/test_nested_offsets__plan0.sql | 98 +- .../test_nested_offsets__plan0_optimized.sql | 24 +- ...ed_offsets_with_time_constraint__plan0.sql | 106 +- ..._with_time_constraint__plan0_optimized.sql | 26 +- ...d_offsets_with_where_constraint__plan0.sql | 104 +- ...with_where_constraint__plan0_optimized.sql | 26 +- ...ry_have_different_granularities__plan0.sql | 262 ++-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 84 +- ...ultiple_granularities__plan0_optimized.sql | 16 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 64 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 26 +- ...ry_have_different_granularities__plan0.sql | 686 +++++----- ...fferent_granularities__plan0_optimized.sql | 26 +- ...w_metric_multiple_granularities__plan0.sql | 332 ++--- ...ultiple_granularities__plan0_optimized.sql | 32 +- ...offset_window_with_agg_time_dim__plan0.sql | 64 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 26 +- ...set_metric_with_time_constraint__plan0.sql | 256 ++-- ..._with_time_constraint__plan0_optimized.sql | 14 +- ...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 +- .../Databricks/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 +- ...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 +- .../Postgres/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 +- ...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 +- .../Redshift/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 +- ...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 +- .../Snowflake/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 +- ...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 +- .../Trino/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 | 20 +- ...fill_nulls_for_one_input_metric__plan0.sql | 502 ++++---- ..._for_one_input_metric__plan0_optimized.sql | 38 +- ...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 | 40 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 18 +- .../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 +- .../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 +- .../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 +- .../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 +- .../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 | 70 +- ...window_with_date_part__plan0_optimized.sql | 26 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 2 +- ...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 | 56 +- ...ffset_to_grain_metric__plan0_optimized.sql | 12 +- ...t_subdaily_offset_window_metric__plan0.sql | 56 +- ..._offset_window_metric__plan0_optimized.sql | 12 +- ...ily_time_constraint_with_metric__plan0.sql | 56 +- ...onstraint_with_metric__plan0_optimized.sql | 19 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 4 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 4 +- ...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 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 6 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 4 +- ...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 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 6 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 4 +- ...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 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 6 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 4 +- ...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 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 6 +- ...st_offset_window_with_date_part__plan0.sql | 74 +- ...window_with_date_part__plan0_optimized.sql | 30 +- .../test_sub_daily_metric_time__plan0.sql | 2 +- ...sub_daily_metric_time__plan0_optimized.sql | 4 +- ...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 +- ...time_constraint_without_metrics__plan0.sql | 2 +- ...raint_without_metrics__plan0_optimized.sql | 6 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 4 +- .../BigQuery/test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 2 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 2 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 6 +- .../test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 4 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 4 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 6 +- .../Postgres/test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 4 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 4 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 6 +- .../Redshift/test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 4 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 4 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 6 +- .../test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 4 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 4 +- ...dimensions_with_time_constraint__plan0.sql | 2 +- ..._with_time_constraint__plan0_optimized.sql | 6 +- .../Trino/test_metric_time_only__plan0.sql | 2 +- ...test_metric_time_only__plan0_optimized.sql | 4 +- .../test_metric_time_quarter_alone__plan0.sql | 2 +- ...tric_time_with_other_dimensions__plan0.sql | 2 +- ...with_other_dimensions__plan0_optimized.sql | 4 +- ...spine_metric_predicate_pushdown__plan0.sql | 1102 ++++++++-------- ...ic_predicate_pushdown__plan0_optimized.sql | 84 +- ..._metric_with_query_time_filters__plan0.sql | 622 ++++----- ...th_query_time_filters__plan0_optimized.sql | 56 +- ...ine_pushdown_filter_application__plan0.sql | 50 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ...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 +- ...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 +- ...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 +- ...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 +- ...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 +- .../test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 2 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- .../test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 4 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- .../test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 4 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- .../test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 4 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- .../test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 4 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- .../Trino/test_min_max_metric_time__plan0.sql | 2 +- ...t_min_max_metric_time__plan0_optimized.sql | 4 +- .../test_min_max_metric_time_week__plan0.sql | 2 +- ...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 +- ...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 +- ...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 +- ...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 +- ...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 +- ...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 +- 756 files changed, 40761 insertions(+), 27009 deletions(-) create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index bdc55673d..ceb5b73c0 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: BigQuery --- -- Compute Metrics via Expressions SELECT - subq_20.metric_time__day - , CAST(subq_20.buys AS FLOAT64) / CAST(NULLIF(subq_20.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 + subq_22.metric_time__day + , CAST(subq_22.buys AS FLOAT64) / CAST(NULLIF(subq_22.visits, 0) AS FLOAT64) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 , GENERATE_UUID() AS mf_internal_uuid FROM ( -- Metric Time Dimension 'ds' SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.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 > DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), INTERVAL 7 day) + subq_10.metric_time__day > DATE_SUB(CAST(subq_13.metric_time__day AS DATETIME), INTERVAL 7 day) ) ) - ) subq_13 - ) subq_14 - ) subq_15 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY metric_time__day - ) subq_16 + ) 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 metric_time__day -) subq_20 +) subq_22 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index c29b49ee4..04e97e0af 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/BigQuery/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 , GENERATE_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 > DATE_SUB(CAST(subq_32.metric_time__day AS DATETIME), INTERVAL 7 day) + sma_28019_cte.metric_time__day > DATE_SUB(CAST(subq_35.metric_time__day AS DATETIME), 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 metric_time__day -) subq_40 +) subq_44 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index 618e405f0..a13eea2d3 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 , 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 > DATEADD(day, -7, subq_12.metric_time__day) + subq_10.metric_time__day > DATEADD(day, -7, subq_13.metric_time__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/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index 054eabc22..388b9302b 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Databricks/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 , 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 > DATEADD(day, -7, subq_32.metric_time__day) + sma_28019_cte.metric_time__day > DATEADD(day, -7, subq_35.metric_time__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/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index 47de6c7fe..a165cce37 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: Postgres --- -- Compute Metrics via Expressions SELECT - subq_20.metric_time__day - , CAST(subq_20.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_20.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 + subq_22.metric_time__day + , CAST(subq_22.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_22.visits, 0) AS DOUBLE PRECISION) 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 - MAKE_INTERVAL(days => 7) + subq_10.metric_time__day > subq_13.metric_time__day - MAKE_INTERVAL(days => 7) ) ) - ) subq_13 - ) subq_14 - ) subq_15 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY - subq_15.metric_time__day - ) subq_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/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index ed8678842..cd6c238dc 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Postgres/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 7) + sma_28019_cte.metric_time__day > subq_35.metric_time__day - MAKE_INTERVAL(days => 7) ) ) - ) 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/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index a6ad786a7..ce8c95d21 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: Redshift --- -- Compute Metrics via Expressions SELECT - subq_20.metric_time__day - , CAST(subq_20.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_20.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 + subq_22.metric_time__day + , CAST(subq_22.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_22.visits, 0) AS DOUBLE PRECISION) 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 , CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid FROM ( -- Metric Time Dimension 'ds' SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.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 > DATEADD(day, -7, subq_12.metric_time__day) + subq_10.metric_time__day > DATEADD(day, -7, subq_13.metric_time__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/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index 3c41d84dc..b7de22a30 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Redshift/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Redshift/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 , CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_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 > DATEADD(day, -7, subq_32.metric_time__day) + sma_28019_cte.metric_time__day > DATEADD(day, -7, subq_35.metric_time__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/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index 83fdc354a..dbab4f915 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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(dayofweekiso 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 , UUID_STRING() AS mf_internal_uuid FROM ( -- Metric Time Dimension 'ds' SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.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 > DATEADD(day, -7, subq_12.metric_time__day) + subq_10.metric_time__day > DATEADD(day, -7, subq_13.metric_time__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/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index 463efd3a5..3e17a6cac 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Snowflake/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Snowflake/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 , UUID_STRING() 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 > DATEADD(day, -7, subq_32.metric_time__day) + sma_28019_cte.metric_time__day > DATEADD(day, -7, subq_35.metric_time__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/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index 10cab4b4e..a39373796 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,47 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 , 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 > DATE_ADD('day', -7, subq_12.metric_time__day) + subq_10.metric_time__day > DATE_ADD('day', -7, subq_13.metric_time__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/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index b354a8d96..9224c66d0 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/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 , 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 > DATE_ADD('day', -7, subq_32.metric_time__day) + sma_28019_cte.metric_time__day > DATE_ADD('day', -7, subq_35.metric_time__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_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql index 01f3d2d54..5e3650655 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: BigQuery --- -- 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 - DATETIME_TRUNC(subq_8.ds, month) AS booking__ds__month - , subq_8.ds AS metric_time__day - , DATETIME_TRUNC(subq_8.ds, isoweek) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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,10 +403,10 @@ FROM ( , 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 booking__ds__month , metric_time__week diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql index 76197cdbc..277353902 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/BigQuery/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -27,38 +27,38 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATETIME_TRUNC(subq_20.ds, month) AS booking__ds__month - , subq_20.ds AS metric_time__day - , DATETIME_TRUNC(subq_20.ds, isoweek) AS metric_time__week - , subq_18.bookers AS bookers - FROM ***************************.mf_time_spine subq_20 + DATETIME_TRUNC(time_spine_src_28006.ds, month) AS booking__ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) 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 - DATETIME_TRUNC(subq_15.ds, month) AS booking__ds__month - , subq_15.ds AS metric_time__day - , DATETIME_TRUNC(subq_15.ds, isoweek) AS metric_time__week + DATETIME_TRUNC(subq_16.ds, month) AS booking__ds__month + , subq_16.ds AS metric_time__day + , DATETIME_TRUNC(subq_16.ds, isoweek) 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 ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_15.ds + DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_16.ds ) AND ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_15.ds AS DATETIME), INTERVAL 2 day) + DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_16.ds AS DATETIME), INTERVAL 2 day) ) GROUP BY booking__ds__month , metric_time__day , metric_time__week - ) subq_18 + ) 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_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql index dc03b367c..14e6ad1f2 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0_optimized.sql index 4a16253b6..9a4804c24 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Databricks/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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) 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_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql index 70d14c500..7855ed0cc 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: Postgres --- -- 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/Postgres/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0_optimized.sql index 417844f92..983a2828c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 2) + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_16.ds - MAKE_INTERVAL(days => 2) ) 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_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql index 941471bd8..261588764 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0_optimized.sql index 5d172a21a..48882b6b0 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Redshift/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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) 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_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql index 227ad2b2b..e40ad6f56 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0_optimized.sql index d98ee20cf..4a5e31a4f 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Snowflake/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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) 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_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql index f3f6aceed..645ca4ee1 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,69 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0_optimized.sql index aa9a15b72..86b0938c5 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/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) > DATE_ADD('day', -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATE_ADD('day', -2, subq_16.ds) ) 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/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index f86e3584b..e576bf10f 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 metric_time__martian_day - ) subq_5 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -235,5 +259,5 @@ FROM ( 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/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index 0f8e2275d..df7653b70 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: BigQuery -- 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 metric_time__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 , DATETIME_TRUNC(ds, day) 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 metric_time__martian_day -) subq_12 +) 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/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 000000000..9df0548b6 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: BigQuery +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATETIME_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATETIME_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATETIME_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATETIME_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATETIME_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 000000000..ad79ec6c6 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: BigQuery +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , DATETIME_TRUNC(ds, day) AS ds__day + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 000000000..1835fbe78 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: BigQuery +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.ds__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATETIME_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATETIME_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATETIME_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATETIME_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATETIME_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATETIME_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATETIME_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 000000000..65ebc1691 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: BigQuery +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , DATETIME_TRUNC(ds, day) AS ds__day + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index f2bd1bad0..0462e6897 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index 0ab8123cd..f9299a4fc 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATETIME_TRUNC(users_ds_source_src_28000.bio_added_ts, month) AS user__bio_added_ts__month - , DATETIME_TRUNC(time_spine_src_28006.ds, day) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATETIME_TRUNC(time_spine_src_28006.ds, day) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0.sql index 059eed683..b1ef40cf6 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index c79e24f13..d0ad89a1c 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATETIME_TRUNC(time_spine_src_28006.ds, day) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0.sql index 26d09dbf6..b22148bbe 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.booking__ds__day AS DATETIME), INTERVAL 5 day) = subq_1.booking__ds__day + DATE_SUB(CAST(subq_4.booking__ds__day AS DATETIME), 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 booking__ds__martian_day - ) subq_7 -) subq_8 + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0_optimized.sql index ac6a6b216..56fd02c5d 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - DATE_SUB(CAST(subq_12.ds AS DATETIME), INTERVAL 5 day) = subq_10.booking__ds__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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 booking__ds__martian_day -) subq_17 +) subq_19 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index 5f8af4c9a..861a34a3f 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), 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 metric_time__day - ) subq_8 -) subq_9 + ) subq_9 +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index 4239dbf28..c2d381e94 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + ) subq_12 ON - DATE_SUB(CAST(subq_13.ds AS DATETIME), INTERVAL 5 day) = subq_11.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index 9f446138a..b3ecbb0e1 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index aca2005c2..58bb0498a 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: Databricks -- 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/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 000000000..38d5c3700 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Databricks +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.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(DAYOFWEEK_ISO 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + subq_8.metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 000000000..378bc1f4f --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Databricks +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 000000000..33f4bfdf8 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Databricks +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.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(DAYOFWEEK_ISO 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 000000000..6d212f73d --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Databricks +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index da4f20ce6..ebd4ec9d5 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index 91a4d3a5c..5e6182ae6 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON @@ -26,4 +26,4 @@ GROUP BY subq_12.martian_day , subq_11.martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) - , DATE_TRUNC('day', time_spine_src_28006.ds) + , time_spine_src_28006.ds diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0.sql index 3afa45323..b058c8129 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index 510f4fce1..4b117f7c8 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY subq_4.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0.sql index 11069c83b..b2f6b57be 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.booking__ds__day) = subq_1.booking__ds__day + DATEADD(day, -5, subq_4.booking__ds__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/Databricks/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0_optimized.sql index cc3c8aeff..b083f7d8f 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -5, subq_12.ds) = subq_10.booking__ds__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index 2b8e2f9a4..e5a162f6a 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day + DATEADD(day, -5, subq_4.metric_time__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/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index e4cb94adb..f72023ccc 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -5, subq_13.ds) = subq_11.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index 45d2f6689..6cd8c0d18 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: Postgres --- -- 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/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index 8387f5d46..6a530c9c5 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: Postgres -- 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/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 000000000..a1a508c5f --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Postgres +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.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_6 + ) subq_7 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + subq_8.metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 000000000..186177923 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Postgres +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 000000000..30af36cdf --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Postgres +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.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_6 + ) subq_7 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 000000000..ca3faae77 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Postgres +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index 08fb093ca..0d67edcdf 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index f456f17c1..653f324f9 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON @@ -26,4 +26,4 @@ GROUP BY subq_12.martian_day , subq_11.martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) - , DATE_TRUNC('day', time_spine_src_28006.ds) + , time_spine_src_28006.ds diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0.sql index a4f123600..95ba609d9 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index f881ddc13..380aa8983 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY subq_4.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0.sql index d044519a2..e936a3449 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 5) = subq_1.booking__ds__day + subq_4.booking__ds__day - MAKE_INTERVAL(days => 5) = 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/Postgres/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0_optimized.sql index 1a03d0f71..7a645df17 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 5) = subq_10.booking__ds__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = 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/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index 31ea2c71a..6c549bd20 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index e5cb95f9b..8e795d4a4 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 5) = subq_11.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = 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_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index d8f039452..d554b12ac 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index bbf4df358..b1e102807 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: Redshift -- 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/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 000000000..ec24e4a85 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Redshift +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + subq_8.metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 000000000..aca8b6dc0 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Redshift +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 000000000..a51ff9318 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Redshift +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 000000000..b9fd40d62 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Redshift +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index f0cd2b74f..1a4710aba 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index 4448310b1..1bc0258fc 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON @@ -26,4 +26,4 @@ GROUP BY subq_12.martian_day , subq_11.martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) - , DATE_TRUNC('day', time_spine_src_28006.ds) + , time_spine_src_28006.ds diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0.sql index 12f9a80c4..22b6d8988 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index 302c60ffb..8fdfeeaff 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY subq_4.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0.sql index 77805a6fd..5a0632c10 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.booking__ds__day) = subq_1.booking__ds__day + DATEADD(day, -5, subq_4.booking__ds__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/Redshift/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0_optimized.sql index 70b91bc6a..6e0433144 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -5, subq_12.ds) = subq_10.booking__ds__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index a98f05803..3f5bbf4ec 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day + DATEADD(day, -5, subq_4.metric_time__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/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index 40e9bafc5..c5b00d512 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -5, subq_13.ds) = subq_11.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index 482668392..0e61d72ab 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index 2cfb7a831..45e33d34c 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: Snowflake -- 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/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 000000000..79ab9ff4a --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Snowflake +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.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(dayofweekiso 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + subq_8.metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 000000000..7fa69b2bb --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Snowflake +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 000000000..bad599105 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Snowflake +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.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(dayofweekiso 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 000000000..eb76773d9 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Snowflake +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index 4cef56366..57bc6b120 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index 961e69d45..139e5479a 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON @@ -26,4 +26,4 @@ GROUP BY subq_12.martian_day , subq_11.martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) - , DATE_TRUNC('day', time_spine_src_28006.ds) + , time_spine_src_28006.ds diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0.sql index b823b8b6f..e06791c75 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index 407b07dfa..68d6d40cb 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY subq_4.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0.sql index f1f3de76b..22ba10b0c 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.booking__ds__day) = subq_1.booking__ds__day + DATEADD(day, -5, subq_4.booking__ds__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/Snowflake/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0_optimized.sql index 8d106e868..1ee62fa02 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -5, subq_12.ds) = subq_10.booking__ds__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index 520ce10b3..8f68c4e82 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day + DATEADD(day, -5, subq_4.metric_time__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/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index e86c0510f..758c9edb4 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -5, subq_13.ds) = subq_11.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index 071d9ac48..fe372816b 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,45 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index 12a7b8a95..df5701142 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: Trino -- 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/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 000000000..8ec6ee8dd --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,376 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Trino +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__martian_day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__martian_day AS metric_time__martian_day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + subq_8.metric_time__martian_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__day + , subq_6.ds__day + , subq_6.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(DAY_OF_WEEK 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__martian_day = '2020-01-01' + ) subq_8 + GROUP BY + subq_8.metric_time__martian_day + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__martian_day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + SELECT + subq_3.metric_time__martian_day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__martian_day + ) subq_5 + ON + subq_9.metric_time__martian_day = subq_5.metric_time__martian_day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 000000000..645afa139 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: Trino +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__martian_day AS metric_time__martian_day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__martian_day',] + SELECT + metric_time__martian_day + FROM ( + -- Read From Time Spine 'mf_time_spine' + -- Transform Time Dimension Columns + SELECT + martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] + -- Aggregate Measures + SELECT + metric_time__martian_day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__martian_day +) subq_16 +ON + subq_20.metric_time__martian_day = subq_16.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 000000000..92cbcf124 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,374 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Trino +--- +-- Compute Metrics via Expressions +SELECT + subq_10.metric_time__day + , subq_10.bookings AS bookings_join_to_time_spine +FROM ( + -- Join to Time Spine Dataset + SELECT + subq_9.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_8.metric_time__day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Transform Time Dimension Columns + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day + , subq_6.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(DAY_OF_WEEK 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__martian_day = '2020-01-01' + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_3.metric_time__day + , subq_3.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__martian_day + , subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.ds_partitioned__day + , subq_2.ds_partitioned__week + , subq_2.ds_partitioned__month + , subq_2.ds_partitioned__quarter + , subq_2.ds_partitioned__year + , subq_2.ds_partitioned__extract_year + , subq_2.ds_partitioned__extract_quarter + , subq_2.ds_partitioned__extract_month + , subq_2.ds_partitioned__extract_day + , subq_2.ds_partitioned__extract_dow + , subq_2.ds_partitioned__extract_doy + , subq_2.paid_at__day + , subq_2.paid_at__week + , subq_2.paid_at__month + , subq_2.paid_at__quarter + , subq_2.paid_at__year + , subq_2.paid_at__extract_year + , subq_2.paid_at__extract_quarter + , subq_2.paid_at__extract_month + , subq_2.paid_at__extract_day + , subq_2.paid_at__extract_dow + , subq_2.paid_at__extract_doy + , subq_2.booking__ds__day + , subq_2.booking__ds__week + , subq_2.booking__ds__month + , subq_2.booking__ds__quarter + , subq_2.booking__ds__year + , subq_2.booking__ds__extract_year + , subq_2.booking__ds__extract_quarter + , subq_2.booking__ds__extract_month + , subq_2.booking__ds__extract_day + , subq_2.booking__ds__extract_dow + , subq_2.booking__ds__extract_doy + , subq_2.booking__ds_partitioned__day + , subq_2.booking__ds_partitioned__week + , subq_2.booking__ds_partitioned__month + , subq_2.booking__ds_partitioned__quarter + , subq_2.booking__ds_partitioned__year + , subq_2.booking__ds_partitioned__extract_year + , subq_2.booking__ds_partitioned__extract_quarter + , subq_2.booking__ds_partitioned__extract_month + , subq_2.booking__ds_partitioned__extract_day + , subq_2.booking__ds_partitioned__extract_dow + , subq_2.booking__ds_partitioned__extract_doy + , subq_2.booking__paid_at__day + , subq_2.booking__paid_at__week + , subq_2.booking__paid_at__month + , subq_2.booking__paid_at__quarter + , subq_2.booking__paid_at__year + , subq_2.booking__paid_at__extract_year + , subq_2.booking__paid_at__extract_quarter + , subq_2.booking__paid_at__extract_month + , subq_2.booking__paid_at__extract_day + , subq_2.booking__paid_at__extract_dow + , subq_2.booking__paid_at__extract_doy + , subq_2.metric_time__day + , subq_2.metric_time__week + , subq_2.metric_time__month + , subq_2.metric_time__quarter + , subq_2.metric_time__year + , subq_2.metric_time__extract_year + , subq_2.metric_time__extract_quarter + , subq_2.metric_time__extract_month + , subq_2.metric_time__extract_day + , subq_2.metric_time__extract_dow + , subq_2.metric_time__extract_doy + , subq_2.listing + , subq_2.guest + , subq_2.host + , subq_2.booking__listing + , subq_2.booking__guest + , subq_2.booking__host + , subq_2.is_instant + , subq_2.booking__is_instant + , subq_2.bookings + , subq_2.instant_bookings + , subq_2.booking_value + , subq_2.max_booking_value + , subq_2.min_booking_value + , subq_2.bookers + , subq_2.average_booking_value + , subq_2.referred_bookings + , subq_2.median_booking_value + , subq_2.booking_value_p99 + , subq_2.discrete_booking_value_p99 + , subq_2.approximate_continuous_booking_value_p99 + , subq_2.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.ds_partitioned__day AS ds_partitioned__day + , subq_0.ds_partitioned__week AS ds_partitioned__week + , subq_0.ds_partitioned__month AS ds_partitioned__month + , subq_0.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_0.ds_partitioned__year AS ds_partitioned__year + , subq_0.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_0.paid_at__day AS paid_at__day + , subq_0.paid_at__week AS paid_at__week + , subq_0.paid_at__month AS paid_at__month + , subq_0.paid_at__quarter AS paid_at__quarter + , subq_0.paid_at__year AS paid_at__year + , subq_0.paid_at__extract_year AS paid_at__extract_year + , subq_0.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_0.paid_at__extract_month AS paid_at__extract_month + , subq_0.paid_at__extract_day AS paid_at__extract_day + , subq_0.paid_at__extract_dow AS paid_at__extract_dow + , subq_0.paid_at__extract_doy AS paid_at__extract_doy + , subq_0.booking__ds__day AS booking__ds__day + , subq_0.booking__ds__week AS booking__ds__week + , subq_0.booking__ds__month AS booking__ds__month + , subq_0.booking__ds__quarter AS booking__ds__quarter + , subq_0.booking__ds__year AS booking__ds__year + , subq_0.booking__ds__extract_year AS booking__ds__extract_year + , subq_0.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_0.booking__ds__extract_month AS booking__ds__extract_month + , subq_0.booking__ds__extract_day AS booking__ds__extract_day + , subq_0.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_0.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day AS booking__paid_at__day + , subq_0.booking__paid_at__week AS booking__paid_at__week + , subq_0.booking__paid_at__month AS booking__paid_at__month + , subq_0.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_0.booking__paid_at__year AS booking__paid_at__year + , subq_0.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_0.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.listing AS listing + , subq_0.guest AS guest + , subq_0.host AS host + , subq_0.booking__listing AS booking__listing + , subq_0.booking__guest AS booking__guest + , subq_0.booking__host AS booking__host + , subq_0.is_instant AS is_instant + , subq_0.booking__is_instant AS booking__is_instant + , subq_0.bookings AS bookings + , subq_0.instant_bookings AS instant_bookings + , subq_0.booking_value AS booking_value + , subq_0.max_booking_value AS max_booking_value + , subq_0.min_booking_value AS min_booking_value + , subq_0.bookers AS bookers + , subq_0.average_booking_value AS average_booking_value + , subq_0.referred_bookings AS referred_bookings + , subq_0.median_booking_value AS median_booking_value + , subq_0.booking_value_p99 AS booking_value_p99 + , subq_0.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + , subq_1.martian_day AS metric_time__martian_day + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 + WHERE metric_time__martian_day = '2020-01-01' + ) subq_3 + ) subq_4 + GROUP BY + subq_4.metric_time__day + ) subq_5 + ON + subq_9.metric_time__day = subq_5.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 000000000..bdc4b3ed1 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -0,0 +1,56 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: Trino +--- +-- Join to Time Spine Dataset +-- Compute Metrics via Expressions +SELECT + subq_20.metric_time__day AS metric_time__day + , subq_16.bookings AS bookings_join_to_time_spine +FROM ( + -- 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 + , martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_18 + WHERE metric_time__martian_day = '2020-01-01' +) subq_20 +LEFT OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Aggregate Measures + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Metric Time Dimension 'ds' + -- Join to Custom Granularity Dataset + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.bookings AS bookings + , subq_12.martian_day AS metric_time__martian_day + 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_11 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_12 + ON + subq_11.ds__day = subq_12.ds + ) subq_13 + WHERE metric_time__martian_day = '2020-01-01' + GROUP BY + metric_time__day +) subq_16 +ON + subq_20.metric_time__day = subq_16.metric_time__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index a560f03bd..121db942f 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -413,7 +413,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index 3af119502..90640bb4d 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -10,14 +10,14 @@ SELECT subq_12.martian_day AS user__bio_added_ts__martian_day , subq_11.martian_day AS metric_time__martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , time_spine_src_28006.ds AS metric_time__day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_11 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.ds + time_spine_src_28006.ds = subq_11.ds LEFT OUTER JOIN ***************************.mf_time_spine subq_12 ON @@ -26,4 +26,4 @@ GROUP BY subq_12.martian_day , subq_11.martian_day , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) - , DATE_TRUNC('day', time_spine_src_28006.ds) + , time_spine_src_28006.ds diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0.sql index ebf291021..fe81fe296 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index abe4c357b..9fee5399e 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ***************************.mf_time_spine subq_4 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_4.ds + time_spine_src_28006.ds = subq_4.ds GROUP BY subq_4.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0.sql index 569610a23..658b8c5cf 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.booking__ds__day) = subq_1.booking__ds__day + DATE_ADD('day', -5, subq_4.booking__ds__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/Trino/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0_optimized.sql index 4ab73ec73..3a83a25a2 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -5, subq_12.ds) = subq_10.booking__ds__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = 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/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index a4430ef8c..28ef9d166 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day + DATE_ADD('day', -5, subq_4.metric_time__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/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index 2ed4e1008..c161c74c5 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -5, subq_13.ds) = subq_11.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = 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_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index cb500cc78..3d87381b9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_5.metric_time__day AS DATETIME), 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 + DATE_SUB(CAST(subq_7.metric_time__day AS DATETIME), 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 metric_time__day - ) subq_10 -) subq_11 + ) subq_11 +) subq_12 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index fd4d509af..3b28e6b43 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_15.ds + DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_16.ds ) AND ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_15.ds AS DATETIME), INTERVAL 2 day) + DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_16.ds AS DATETIME), INTERVAL 2 day) ) - ) subq_16 + ) subq_17 ON - DATE_SUB(CAST(subq_18.ds AS DATETIME), INTERVAL 2 day) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_17.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY metric_time__day -) subq_23 +) subq_25 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index a8ff00ed4..068de1d34 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 - DATETIME_TRUNC(subq_3.ds, month) 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 + , DATETIME_TRUNC(time_spine_src_16006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_16006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_16006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_16006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_16006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_16006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 metric_time__month - ) subq_2 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -99,10 +121,10 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_SUB(CAST(subq_2.metric_time__month AS DATETIME), INTERVAL 1 month) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__month AS DATETIME), INTERVAL 1 month) = subq_1.metric_time__month + ) subq_5 + ) subq_6 GROUP BY metric_time__month - ) subq_6 -) subq_7 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 9bad19fa7..d8e371247 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 DATETIME_TRUNC(ds, month) AS metric_time__month - FROM ***************************.mf_time_spine subq_11 + FROM ***************************.mf_time_spine time_spine_src_16006 GROUP BY metric_time__month - ) subq_10 + ) subq_13 INNER JOIN ***************************.fct_bookings_extended_monthly monthly_bookings_source_src_16000 ON - DATE_SUB(CAST(subq_10.metric_time__month AS DATETIME), INTERVAL 1 month) = DATETIME_TRUNC(monthly_bookings_source_src_16000.ds, month) + DATE_SUB(CAST(subq_13.metric_time__month AS DATETIME), INTERVAL 1 month) = DATETIME_TRUNC(monthly_bookings_source_src_16000.ds, month) GROUP BY metric_time__month -) subq_15 +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql index 527d9d0a4..c64e67df8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_7.metric_time__day, month) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATETIME_TRUNC(subq_9.metric_time__day, month) = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY metric_time__day - ) subq_11 - ) subq_12 + ) 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 metric_time__day -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index a3b05090c..7efbb828b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATETIME_TRUNC(subq_22.ds, month) = subq_20.metric_time__day + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_21.metric_time__day GROUP BY metric_time__day - ) subq_26 + ) 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 metric_time__day -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 6b8f5a9d6..031cde075 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_8.ds, isoweek) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_7.metric_time__day, month) = subq_6.metric_time__day - WHERE subq_7.metric_time__week = subq_7.metric_time__day - ) subq_9 - ) subq_10 + DATETIME_TRUNC(subq_9.metric_time__day, month) = subq_6.metric_time__day + WHERE subq_9.metric_time__week = subq_9.metric_time__day + ) subq_10 + ) subq_11 GROUP BY metric_time__week - ) subq_11 - ) subq_12 + ) 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 metric_time__week -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 69b5a61e8..7d375865c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, isoweek) 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 - DATETIME_TRUNC(subq_22.ds, isoweek) AS metric_time__week - , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATETIME_TRUNC(subq_22.ds, month) = subq_20.metric_time__day - WHERE DATETIME_TRUNC(subq_22.ds, isoweek) = subq_22.ds + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_21.metric_time__day + WHERE DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) = time_spine_src_28006.ds GROUP BY metric_time__week - ) subq_26 + ) 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 metric_time__week -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql index d4a80aad4..de146d1fe 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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_SUB(CAST(subq_7.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY metric_time__day - ) subq_11 - ) subq_12 + ) 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 metric_time__day -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0_optimized.sql index fa0b0ca3b..a183fb5ac 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_SUB(CAST(subq_22.ds AS DATETIME), INTERVAL 14 day) = subq_20.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = subq_21.metric_time__day GROUP BY metric_time__day - ) subq_26 + ) 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 metric_time__day -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 8d30776e8..007c6e96d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_8.ds, quarter) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_7.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY metric_time__quarter - ) subq_11 - ) subq_12 + ) 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 metric_time__quarter -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index cc6350e6d..a2f15818a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, quarter) 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 - DATETIME_TRUNC(subq_22.ds, quarter) AS metric_time__quarter - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + DATETIME_TRUNC(time_spine_src_28006.ds, quarter) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_SUB(CAST(subq_22.ds AS DATETIME), INTERVAL 14 day) = subq_20.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = subq_21.metric_time__day GROUP BY metric_time__quarter - ) subq_26 + ) 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 metric_time__quarter -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index ec3e167f1..bb9d279e6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_2.metric_time__day, month) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATETIME_TRUNC(subq_4.metric_time__day, month) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day - ) subq_6 - ) subq_7 + ) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_10.metric_time__day AS DATETIME), INTERVAL 1 month) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_SUB(CAST(subq_13.metric_time__day AS DATETIME), INTERVAL 1 month) = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY metric_time__day - ) subq_14 - ) subq_15 + ) 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 metric_time__day -) subq_16 +) subq_18 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index a0e830b69..cf94a9661 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_18 + ) subq_20 ON - DATETIME_TRUNC(subq_20.ds, month) = subq_18.metric_time__day + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_20.metric_time__day GROUP BY metric_time__day - ) subq_24 + ) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - DATE_SUB(CAST(subq_28.ds AS DATETIME), INTERVAL 1 month) = subq_26.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 month) = subq_29.metric_time__day GROUP BY metric_time__day - ) subq_32 + ) 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 metric_time__day -) subq_33 +) subq_37 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 1a2e246f6..af1c06d02 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_3.ds, year) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_2.metric_time__day, month) = subq_1.metric_time__day - WHERE subq_2.metric_time__year = subq_2.metric_time__day - ) subq_4 - ) subq_5 + DATETIME_TRUNC(subq_4.metric_time__day, month) = subq_1.metric_time__day + WHERE subq_4.metric_time__year = subq_4.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__year - ) subq_6 - ) subq_7 + ) 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 - , DATETIME_TRUNC(subq_11.ds, year) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_10.metric_time__day AS DATETIME), INTERVAL 1 month) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_SUB(CAST(subq_13.metric_time__day AS DATETIME), INTERVAL 1 month) = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY metric_time__year - ) subq_14 - ) subq_15 + ) 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 metric_time__year -) subq_16 +) subq_18 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 8f7ccace5..6c87cda87 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 - DATETIME_TRUNC(subq_20.ds, year) AS metric_time__year - , SUM(subq_18.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_18 + ) subq_20 ON - DATETIME_TRUNC(subq_20.ds, month) = subq_18.metric_time__day - WHERE DATETIME_TRUNC(subq_20.ds, year) = subq_20.ds + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_20.metric_time__day + WHERE DATETIME_TRUNC(time_spine_src_28006.ds, year) = time_spine_src_28006.ds GROUP BY metric_time__year - ) subq_24 + ) subq_27 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__year'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATETIME_TRUNC(subq_28.ds, year) AS metric_time__year - , SUM(subq_26.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_28 + DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - DATE_SUB(CAST(subq_28.ds AS DATETIME), INTERVAL 1 month) = subq_26.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 month) = subq_29.metric_time__day GROUP BY metric_time__year - ) subq_32 + ) 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 metric_time__year -) subq_33 +) subq_37 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index f2749ad4a..7385ebc30 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_8.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_7.metric_time__day - ) subq_10 + DATE_SUB(CAST(subq_10.metric_time__day AS DATETIME), 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 metric_time__day - ) subq_13 - ) subq_14 + ) 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 metric_time__day -) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index 5fc91ceab..bb75d4d6f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_23 + ) subq_24 ON - DATE_SUB(CAST(subq_25.ds AS DATETIME), INTERVAL 14 day) = subq_23.metric_time__day - ) subq_26 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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 metric_time__day -) subq_31 +) subq_33 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql index 06985ad46..535e2668f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_5.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + DATE_SUB(CAST(subq_7.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_4.metric_time__day + ) subq_8 + ) subq_9 GROUP BY metric_time__day - ) subq_9 -) subq_10 + ) subq_10 +) subq_11 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0_optimized.sql index b66ab403f..400b3fa43 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_14.ds + DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_15.ds ) AND ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_14.ds AS DATETIME), INTERVAL 2 day) + DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_15.ds AS DATETIME), INTERVAL 2 day) ) - ) subq_15 + ) subq_16 ON - DATE_SUB(CAST(subq_17.ds AS DATETIME), INTERVAL 2 day) = subq_15.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_16.metric_time__day GROUP BY metric_time__day -) subq_21 +) subq_23 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 2d791b43a..b50ba9bcb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.booking__ds__day AS DATETIME), INTERVAL 1 week) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.booking__ds__day AS DATETIME), INTERVAL 1 week) = subq_1.booking__ds__day + ) subq_5 + ) subq_6 GROUP BY booking__ds__day - ) subq_6 - ) subq_7 + ) 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 booking__ds__day - ) subq_11 - ) subq_12 + ) 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 booking__ds__day -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index 3e333677d..179d1ed98 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 - DATE_SUB(CAST(subq_17.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) GROUP BY booking__ds__day - ) subq_21 + ) 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 booking__ds__day - ) 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 booking__ds__day -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql index 58fb1dddb..12f14d3b0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day - ) subq_6 -) subq_7 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index fcc4c1501..63ebed0c4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 ON - DATE_SUB(CAST(subq_11.ds AS DATETIME), INTERVAL 5 day) = subq_9.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_10.metric_time__day GROUP BY metric_time__day -) subq_15 +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 4a81cecb7..715959da9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day , booking__is_instant - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_8.metric_time__day - ) subq_11 + DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), 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/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 14f557c69..95f6f4f23 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 - DATE_SUB(CAST(subq_17.ds AS DATETIME), INTERVAL 5 day) = subq_15.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_17.metric_time__day GROUP BY metric_time__day , booking__is_instant - ) subq_21 - ) subq_22 + ) subq_24 + ) subq_25 ON - DATE_SUB(CAST(subq_24.ds AS DATETIME), INTERVAL 2 day) = subq_22.metric_time__day - ) subq_25 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index 1e108238e..de831535b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_6.metric_time__day, month) = subq_5.metric_time__day - ) subq_8 + DATETIME_TRUNC(subq_8.metric_time__day, month) = 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 metric_time__day - ) subq_12 - ) subq_13 - ) subq_14 + ) 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 metric_time__day -) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 07eb7ffae..db075ed7a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 metric_time__day - ) subq_20 - ) subq_21 + ) subq_21 + ) subq_22 ON - DATETIME_TRUNC(subq_23.ds, month) = subq_21.metric_time__day - ) subq_24 + DATETIME_TRUNC(time_spine_src_28006.ds, month) = 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 metric_time__day - ) 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 metric_time__day -) subq_31 +) subq_33 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql index 04e0bb15f..ef9272fb0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_8.metric_time__day -) subq_11 + DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0_optimized.sql index 14d59bc46..6af166cd3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_15 ON - DATE_SUB(CAST(subq_15.ds AS DATETIME), INTERVAL 5 day) = subq_13.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_15.metric_time__day GROUP BY metric_time__day - ) subq_19 - ) subq_20 + ) subq_22 + ) subq_23 ON - DATE_SUB(CAST(subq_22.ds AS DATETIME), INTERVAL 2 day) = subq_20.metric_time__day -) subq_23 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql index 3c020e799..019f1565b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), 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 + DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), 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/BigQuery/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 4183500d0..0f735319d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_16 ON - DATE_SUB(CAST(subq_16.ds AS DATETIME), INTERVAL 5 day) = subq_14.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_16.metric_time__day GROUP BY metric_time__day - ) subq_20 - ) subq_21 + ) subq_23 + ) subq_24 ON - DATE_SUB(CAST(subq_23.ds AS DATETIME), INTERVAL 2 day) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_24.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql index bc4faccfd..a10b0fac8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 5 day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_8.metric_time__day - ) subq_11 + DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), 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/BigQuery/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 974fba188..46d542366 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_16 ON - DATE_SUB(CAST(subq_16.ds AS DATETIME), INTERVAL 5 day) = subq_14.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_16.metric_time__day GROUP BY metric_time__day - ) subq_20 - ) subq_21 + ) subq_23 + ) subq_24 ON - DATE_SUB(CAST(subq_23.ds AS DATETIME), INTERVAL 2 day) = subq_21.metric_time__day - ) subq_24 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 2 day) = subq_24.metric_time__day + ) subq_28 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' -) subq_25 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 1393c9284..fea5eb2a6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_3.ds, month) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_2.metric_time__day, month) = subq_1.metric_time__day - WHERE subq_2.metric_time__month = subq_2.metric_time__day - ) subq_4 + DATETIME_TRUNC(subq_4.metric_time__day, month) = 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 metric_time__month - ) subq_7 -) subq_8 + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 9b2141086..3aa8c518d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 - , DATETIME_TRUNC(subq_12.ds, month) AS metric_time__month - , subq_10.bookings AS bookings - FROM ***************************.mf_time_spine subq_12 + time_spine_src_28006.ds AS metric_time__day + , DATETIME_TRUNC(time_spine_src_28006.ds, month) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - DATETIME_TRUNC(subq_12.ds, month) = subq_10.metric_time__day - WHERE DATETIME_TRUNC(subq_12.ds, month) = subq_12.ds - ) subq_13 + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_11.metric_time__day + WHERE DATETIME_TRUNC(time_spine_src_28006.ds, month) = 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/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql index 6adab29d6..03586ac35 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_3.ds, month) AS metric_time__month - , DATETIME_TRUNC(subq_3.ds, year) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_2.metric_time__day, month) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATETIME_TRUNC(subq_4.metric_time__day, month) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day , metric_time__month , metric_time__year - ) subq_6 -) subq_7 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index 039f084b2..d40e57e9a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 - , DATETIME_TRUNC(subq_11.ds, month) AS metric_time__month - , DATETIME_TRUNC(subq_11.ds, year) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS metric_time__month + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 ON - DATETIME_TRUNC(subq_11.ds, month) = subq_9.metric_time__day + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_10.metric_time__day GROUP BY metric_time__day , metric_time__month , metric_time__year -) subq_15 +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql index c05bb94ed..14a79cfa6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_7.booking__ds__day, month) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATETIME_TRUNC(subq_9.booking__ds__day, month) = subq_6.booking__ds__day + ) subq_10 + ) subq_11 GROUP BY booking__ds__day - ) subq_11 - ) subq_12 + ) 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 booking__ds__day -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index fb7460574..ebf08d82a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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 ( DATETIME_TRUNC(ds, day) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATETIME_TRUNC(subq_22.ds, month) = subq_20.booking__ds__day + DATETIME_TRUNC(time_spine_src_28006.ds, month) = subq_21.booking__ds__day GROUP BY booking__ds__day - ) subq_26 + ) 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 booking__ds__day -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index e5b6bdae7..b72047f3e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_3.ds, month) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 1 week) = subq_1.metric_time__day - ) subq_4 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), 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 metric_time__month - ) subq_7 - ) subq_8 + ) 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 metric_time__month - ) subq_13 - ) subq_14 + ) 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 metric_time__month -) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 73536fe94..74db443df 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 - , DATETIME_TRUNC(subq_19.ds, month) AS metric_time__month + time_spine_src_28006.ds AS metric_time__day + , DATETIME_TRUNC(time_spine_src_28006.ds, month) 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 - DATE_SUB(CAST(subq_19.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) - ) subq_20 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) + ) 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 ( , DATETIME_TRUNC(ds, month) 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 metric_time__month -) subq_31 +) subq_33 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql index 5e4750080..dce20780a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_3.ds, month) AS metric_time__month - , DATETIME_TRUNC(subq_3.ds, year) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 1 week) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), INTERVAL 1 week) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY metric_time__day , metric_time__month , metric_time__year - ) subq_6 - ) subq_7 + ) 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 metric_time__day , metric_time__month , metric_time__year - ) subq_11 - ) subq_12 + ) 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 metric_time__day , metric_time__month , metric_time__year -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index a913e59a6..17b2bfbc1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 - , DATETIME_TRUNC(subq_17.ds, month) AS metric_time__month - , DATETIME_TRUNC(subq_17.ds, year) AS metric_time__year + time_spine_src_28006.ds AS metric_time__day + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS metric_time__month + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 - DATE_SUB(CAST(subq_17.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 week) = DATETIME_TRUNC(bookings_source_src_28000.ds, day) GROUP BY metric_time__day , metric_time__month , metric_time__year - ) subq_21 + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -54,17 +54,17 @@ FROM ( metric_time__day , metric_time__month , metric_time__year - ) 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 metric_time__day , metric_time__month , metric_time__year -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql index d5a8ac8ec..2eeeebc28 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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_SUB(CAST(subq_7.booking__ds__day AS DATETIME), INTERVAL 14 day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATE_SUB(CAST(subq_9.booking__ds__day AS DATETIME), INTERVAL 14 day) = subq_6.booking__ds__day + ) subq_10 + ) subq_11 GROUP BY booking__ds__day - ) subq_11 - ) subq_12 + ) 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 booking__ds__day -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0_optimized.sql index 201002c96..b0e2c3491 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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 ( DATETIME_TRUNC(ds, day) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_SUB(CAST(subq_22.ds AS DATETIME), INTERVAL 14 day) = subq_20.booking__ds__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = subq_21.booking__ds__day GROUP BY booking__ds__day - ) subq_26 + ) 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 booking__ds__day -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql index 0e9e30db3..c0dbb90fb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), 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 + DATE_SUB(CAST(subq_4.metric_time__day AS DATETIME), 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 metric_time__day - ) subq_7 -) subq_8 + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index 3bc29dc98..423c4e115 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - DATE_SUB(CAST(subq_12.ds AS DATETIME), INTERVAL 5 day) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 5 day) = subq_11.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY metric_time__day -) subq_17 +) subq_19 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 850c8a246..04f145bdf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(day, -2, subq_5.metric_time__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 + DATEADD(day, -2, subq_7.metric_time__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/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index 8324d90b8..463757684 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) - ) subq_16 + ) subq_17 ON - DATEADD(day, -2, subq_18.ds) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 3dabd090e..e0af5e59f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(month, -1, subq_2.metric_time__month) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + DATEADD(month, -1, subq_4.metric_time__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/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 8dca63379..961743f33 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(month, -1, subq_10.metric_time__month) = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + DATEADD(month, -1, subq_13.metric_time__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/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql index 134685c6e..c428753d6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index 1e504f020..99028cc6c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index f09d32e7e..663e1a38b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 0422c7745..33f035ee7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql index 16136ee1f..dbe1b78aa 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Databricks/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0_optimized.sql index cf81e784d..1b8ce9efe 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, 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/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 5bf84c68d..5ae5a0cfa 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index f38cb7d2b..16bd08a0c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 5d7d7aa3e..03fa20d24 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__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_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index be9642ae8..bd55d23ba 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = 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/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 011efcbf1..c2b0043f3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__day) = 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/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 55bf083f4..1867dd46a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = 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/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 10dc33073..14b1115c0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_8.metric_time__day) = subq_7.metric_time__day - ) subq_10 + DATEADD(day, -14, subq_10.metric_time__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/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index f5faf4483..67723dbb6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -14, subq_25.ds) = subq_23.metric_time__day - ) subq_26 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Databricks/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql index 636ea606b..0aad53b97 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(day, -2, subq_5.metric_time__day) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + DATEADD(day, -2, subq_7.metric_time__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/Databricks/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0_optimized.sql index 46f8a04db..ee2e66dce 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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) > DATEADD(day, -2, subq_14.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_15.ds) ) - ) subq_15 + ) subq_16 ON - DATEADD(day, -2, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 88b69a224..15a1d9274 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(week, -1, subq_2.booking__ds__day) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, subq_4.booking__ds__day) = 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/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index 78ae26a9e..e0d84b6db 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql index f9d8141dd..a4aae294c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index ef9112432..a466307d4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -5, subq_11.ds) = subq_9.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 8d0f38217..6a93ac55d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, subq_4.metric_time__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 - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 6e2e83b47..89bcc32f7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -5, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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 - DATEADD(day, -2, subq_24.ds) = subq_22.metric_time__day - ) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index e8867090b..721bb6fba 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 3c7b7bd4b..9803cab01 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql index 2a162caea..161b49104 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day -) subq_11 + DATEADD(day, -2, subq_12.metric_time__day) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0_optimized.sql index afed1816e..9aec36d40 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -5, subq_15.ds) = subq_13.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - DATEADD(day, -2, subq_22.ds) = subq_20.metric_time__day -) subq_23 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql index 2b0efba5c..7b18790e8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 - WHERE subq_11.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' -) subq_12 + DATEADD(day, -2, subq_12.metric_time__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/Databricks/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 8b3aac867..837d11c0c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql index 4492ea2f3..44df912e8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Databricks/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0_optimized.sql index ec6b4352f..7f46354fc 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - ) subq_24 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 47a841cb2..f92202ef8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index a45feb035..8951bbe9e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql index 976e8404a..cca0e2f84 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index 5b6603fdf..34497b505 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql index 62cf1b225..ca3c4ba8f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index c76a35a7a..9ab53f709 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index decfdb0be..466fa889c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 + DATEADD(week, -1, subq_4.metric_time__day) = 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/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 0acbd8cac..3b39350ff 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(week, -1, subq_19.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql index 151fbd171..ff2d3d11f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, 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 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/Databricks/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 6d98d432d..d4c2b8ec7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Databricks/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql index 737cfa0f1..66bd07401 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Databricks/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0_optimized.sql index 38008ad1e..403b51d55 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -14, subq_22.ds) = subq_20.booking__ds__day + DATEADD(day, -14, 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/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql index 9440ae12f..99631e191 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(day, -5, subq_2.metric_time__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 + DATEADD(day, -5, subq_4.metric_time__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/Databricks/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index 92a8d0976..93a5ebbb6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -5, subq_12.ds) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -5, time_spine_src_28006.ds) = 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_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 657ae62d6..b6f6922d4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 2) = 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 - MAKE_INTERVAL(days => 2) = 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/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index c035b82dd..7bdf364b9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 2) + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_16.ds - MAKE_INTERVAL(days => 2) ) - ) subq_16 + ) subq_17 ON - subq_18.ds - MAKE_INTERVAL(days => 2) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = 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/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 4e96546ef..e85d050b4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(months => 1) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + subq_4.metric_time__month - MAKE_INTERVAL(months => 1) = 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/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 34b51248a..fa50f3881 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(months => 1) = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + subq_13.metric_time__month - MAKE_INTERVAL(months => 1) = 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/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql index 783a3b9c0..6d326e038 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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/Postgres/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index ece4b86e4..6e76fc93f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 57f3a8197..e67ed0bf7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 32cb49a8e..0cb63ea03 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql index 612cd1565..584ab1d27 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 14) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0_optimized.sql index 9e88eaf12..0846df3c8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 14) = subq_20.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql index a3c11f652..5560daee9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 14) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index 53a9fe09c..7140e9168 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 14) = subq_20.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 0d5148276..0603a435b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(months => 1) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - MAKE_INTERVAL(months => 1) = 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/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 97deaf2d8..877e42810 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(months => 1) = subq_26.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(months => 1) = 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/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 834c12c2f..e5bee98df 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(months => 1) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - MAKE_INTERVAL(months => 1) = 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/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index d5a61f7a8..f2b523f0b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(months => 1) = subq_26.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(months => 1) = 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/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 69c1c7eeb..6f7dd004c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 14) = subq_7.metric_time__day - ) subq_10 + subq_10.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index 2f0e94a1b..7a86dcc46 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 14) = subq_23.metric_time__day - ) subq_26 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql index ef5e72141..d2769c6a2 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 2) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + subq_7.metric_time__day - MAKE_INTERVAL(days => 2) = 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/Postgres/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0_optimized.sql index 1329a0ade..397127145 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 2) + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - MAKE_INTERVAL(days => 2) ) - ) subq_15 + ) subq_16 ON - subq_17.ds - MAKE_INTERVAL(days => 2) = subq_15.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = 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/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 49d2b87f0..b1054a07b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(weeks => 1) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + subq_4.booking__ds__day - MAKE_INTERVAL(weeks => 1) = 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/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index 2f6371d3f..334eb347a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(weeks => 1) = DATE_TRUNC('day', bookings_source_src_28000.ds) + time_spine_src_28006.ds - MAKE_INTERVAL(weeks => 1) = 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/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql index 23f3c3659..d4b8eb0b3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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/Postgres/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index 814f94c4a..715adafa6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 5) = subq_9.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = 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/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index e905ef777..2e5d8fd78 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = subq_8.metric_time__day - ) subq_11 + subq_12.metric_time__day - MAKE_INTERVAL(days => 2) = 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/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index c11fef9c7..cd6a43d88 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 5) = subq_15.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = subq_22.metric_time__day - ) subq_25 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = 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/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index 84366e4d4..7b9c96bc8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: Postgres --- -- 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/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 2f8d1a2c5..ea13211df 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql index 0cbb871dd..f504a248c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = subq_8.metric_time__day -) subq_11 + subq_12.metric_time__day - MAKE_INTERVAL(days => 2) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0_optimized.sql index ba241866d..0cf2bf281 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 5) = subq_13.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = subq_20.metric_time__day -) subq_23 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql index 37735affc..56a0c6ffe 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = 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 - MAKE_INTERVAL(days => 2) = 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/Postgres/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0_optimized.sql index ad70412fd..47a6aadd2 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 5) = subq_14.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = subq_24.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql index b84203131..c91a63071 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 5) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = subq_8.metric_time__day - ) subq_11 + subq_12.metric_time__day - MAKE_INTERVAL(days => 2) = 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/Postgres/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 0aa067052..52405830a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 5) = subq_14.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 2) = subq_21.metric_time__day - ) subq_24 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 2) = subq_24.metric_time__day + ) subq_28 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' -) subq_25 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 743886eea..352f9581d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: Postgres --- -- 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/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 52f737090..6bc6a3336 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql index b4ff6725d..a8d7c2596 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: Postgres --- -- 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/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index 321cb4ac6..bb00b76d5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql index d80383f1b..aecfd7e33 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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/Postgres/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index e102ca870..aa15d6d62 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index 873e4a30d..ed7b7f3c3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(weeks => 1) = subq_1.metric_time__day - ) subq_4 + subq_4.metric_time__day - MAKE_INTERVAL(weeks => 1) = 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/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 3934f7c7b..e6c54c903 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(weeks => 1) = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + time_spine_src_28006.ds - MAKE_INTERVAL(weeks => 1) = 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/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql index c38d5049a..a0378db4c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(weeks => 1) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - MAKE_INTERVAL(weeks => 1) = 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/Postgres/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 34c12c7bd..cd44a509e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(weeks => 1) = DATE_TRUNC('day', bookings_source_src_28000.ds) + time_spine_src_28006.ds - MAKE_INTERVAL(weeks => 1) = 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/Postgres/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql index 9e2938236..c394be598 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 14) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + subq_9.booking__ds__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0_optimized.sql index 9d3549dd5..da8dd9be7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 14) = subq_20.booking__ds__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql index 6d0b70780..96be1c4ae 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 5) = 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 - MAKE_INTERVAL(days => 5) = 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/Postgres/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index 773cb85a3..1f8335e0a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 5) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + time_spine_src_28006.ds - MAKE_INTERVAL(days => 5) = 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_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 9b22b1037..b40be0e25 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -2, subq_5.metric_time__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 + DATEADD(day, -2, subq_7.metric_time__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/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index 54fdaf938..bbaf908dc 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) - ) subq_16 + ) subq_17 ON - DATEADD(day, -2, subq_18.ds) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index d16d4843a..d310236c9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_16006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_16006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_16006.ds) END 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 - DATEADD(month, -1, subq_2.metric_time__month) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + DATEADD(month, -1, subq_4.metric_time__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/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 9b19e89db..2d2800da4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(month, -1, subq_10.metric_time__month) = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + DATEADD(month, -1, subq_13.metric_time__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/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql index c299b86a8..c3f5df6b5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index 464cffe60..5c7d16d46 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index e956f057e..ca7a5e557 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index d9147b7bd..33677b9b0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql index aad61e85c..2d84352f9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Redshift/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0_optimized.sql index cfa62f92a..f5ce56a3c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, 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/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 52e6be646..6efb4d571 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index b6bc0d71d..cc4faaa11 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index d30aaa07e..57bfed7c7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__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_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index f23d4f512..b427c8b0d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = 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/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index c0ffbc4b6..8a73b7b63 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__day) = 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/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index c0e2a731e..0a65fe952 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = 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/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 511363bfc..3e0a8be65 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_8.metric_time__day) = subq_7.metric_time__day - ) subq_10 + DATEADD(day, -14, subq_10.metric_time__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/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index 398662084..cc4d410ae 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -14, subq_25.ds) = subq_23.metric_time__day - ) subq_26 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Redshift/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql index c1818c710..56d6747cf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -2, subq_5.metric_time__day) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + DATEADD(day, -2, subq_7.metric_time__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/Redshift/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0_optimized.sql index 28071a31e..95d782834 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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) > DATEADD(day, -2, subq_14.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_15.ds) ) - ) subq_15 + ) subq_16 ON - DATEADD(day, -2, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 6932f490e..87480251d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(week, -1, subq_2.booking__ds__day) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, subq_4.booking__ds__day) = 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/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index 67fe080a8..4ed8e2a49 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql index b93df27b7..e56ffec81 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index 6b9a08d0b..e488fdb3f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -5, subq_11.ds) = subq_9.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 9eb7ee206..b6c41e336 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, subq_4.metric_time__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 - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 606a9fa31..e2a58e966 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -5, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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 - DATEADD(day, -2, subq_24.ds) = subq_22.metric_time__day - ) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index 77c4a6146..e8ac67205 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 38559a01a..6950c8a6a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql index 77928c9c0..9f2e2553d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day -) subq_11 + DATEADD(day, -2, subq_12.metric_time__day) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0_optimized.sql index 858599a4b..78c6b87a9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -5, subq_15.ds) = subq_13.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - DATEADD(day, -2, subq_22.ds) = subq_20.metric_time__day -) subq_23 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql index 6619dd6f2..f906b5884 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 - WHERE subq_11.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' -) subq_12 + DATEADD(day, -2, subq_12.metric_time__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/Redshift/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0_optimized.sql index a0cd96d15..abff7fdb5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql index b2226271d..c8fceb70b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Redshift/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 3d6418dab..b75545623 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - ) subq_24 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 1042220d4..6cffa81f1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index e2ef45757..6877e3ae6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql index a88c011d0..b454a6bc9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index e47d7558a..778cb9215 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql index fcd186794..f2dbceb18 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index 3aefd9bee..ed4b519e9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index d29251813..d7c96e7eb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 + DATEADD(week, -1, subq_4.metric_time__day) = 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/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 2608a60ba..7d3273439 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(week, -1, subq_19.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql index 8d3d0df11..68aaf926f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, 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 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/Redshift/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 22753736d..fe772da49 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Redshift/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql index d6994b9aa..1ae85f2d3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Redshift/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0_optimized.sql index c0f274803..10dcb076d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -14, subq_22.ds) = subq_20.booking__ds__day + DATEADD(day, -14, 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/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql index 9ff738e78..efab319db 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -5, subq_2.metric_time__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 + DATEADD(day, -5, subq_4.metric_time__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/Redshift/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index eb8f6a54d..ab218ad8f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -5, subq_12.ds) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -5, time_spine_src_28006.ds) = 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_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 6a112a6e5..f21741074 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(day, -2, subq_5.metric_time__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 + DATEADD(day, -2, subq_7.metric_time__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/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index f20bb5198..5929f7bc2 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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) > DATEADD(day, -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_16.ds) ) - ) subq_16 + ) subq_17 ON - DATEADD(day, -2, subq_18.ds) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index b1c9634d3..67bfb650e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(month, -1, subq_2.metric_time__month) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + DATEADD(month, -1, subq_4.metric_time__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/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 198624f2f..4b63f35ac 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(month, -1, subq_10.metric_time__month) = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + DATEADD(month, -1, subq_13.metric_time__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/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql index 8c9de2b85..4bf050c36 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index f61138cd3..4027bad0c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 093d19c38..0f27bed4b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 9d2b8b9ae..d23d8d8f6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql index 7217c5360..bc9846195 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Snowflake/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0_optimized.sql index ce55aa295..de25cf317 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, 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/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 2fb4b0f8c..7f6670929 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index 8b3679742..bc333100d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 9b9427974..d6346015d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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(dayofweekiso 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__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_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index a19241a8b..ae8d090a2 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = 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/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index ddf8b9555..7bf8837ad 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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(dayofweekiso 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 - DATEADD(month, -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(month, -1, subq_13.metric_time__day) = 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/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index b8eb112e7..ac32f4867 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(month, -1, subq_28.ds) = subq_26.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = 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/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index e8efb7582..715014b27 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(day, -14, subq_8.metric_time__day) = subq_7.metric_time__day - ) subq_10 + DATEADD(day, -14, subq_10.metric_time__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/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index f8f10fb73..35eaf9c55 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -14, subq_25.ds) = subq_23.metric_time__day - ) subq_26 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Snowflake/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql index a0c24f4ad..4e004941e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(day, -2, subq_5.metric_time__day) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + DATEADD(day, -2, subq_7.metric_time__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/Snowflake/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0_optimized.sql index 3776496f5..daf33313b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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) > DATEADD(day, -2, subq_14.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_15.ds) ) - ) subq_15 + ) subq_16 ON - DATEADD(day, -2, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 5414acdf4..bc31285d0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(week, -1, subq_2.booking__ds__day) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, subq_4.booking__ds__day) = 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/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index 88b862779..20244a516 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql index 460c155b0..070226546 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index a603ed6aa..915d96de6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -5, subq_11.ds) = subq_9.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 0d33e4046..20fd7b6cf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, subq_4.metric_time__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 - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 9388c1fcc..be9fa2df7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -5, subq_17.ds) = subq_15.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = 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 - DATEADD(day, -2, subq_24.ds) = subq_22.metric_time__day - ) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index afbe9604b..1f475b614 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 58da2a3cc..f8b59c400 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql index dde312e10..9970d15e3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day -) subq_11 + DATEADD(day, -2, subq_12.metric_time__day) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0_optimized.sql index f750dc648..b21ee2333 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -5, subq_15.ds) = subq_13.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - DATEADD(day, -2, subq_22.ds) = subq_20.metric_time__day -) subq_23 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql index 4b8fa3ee3..c4fb439ef 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 - WHERE subq_11.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' -) subq_12 + DATEADD(day, -2, subq_12.metric_time__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/Snowflake/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 68d9df184..96fb239f1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + DATEADD(day, -2, time_spine_src_28006.ds) = subq_24.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql index 0942c73ff..90dec6ff3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(day, -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATEADD(day, -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATEADD(day, -2, subq_12.metric_time__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/Snowflake/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0_optimized.sql index d23fbf4a1..1b0f2830a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -5, subq_16.ds) = subq_14.metric_time__day + DATEADD(day, -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATEADD(day, -2, subq_23.ds) = subq_21.metric_time__day - ) subq_24 + DATEADD(day, -2, time_spine_src_28006.ds) = 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/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 43431536d..c011099a7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 2fec95707..39d096eeb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql index d01f96513..ad31de341 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index d270f2280..44ec893a1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql index cb56bf555..20fb82cd8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index cc5e1978f..0a55ccb19 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index 38eae4d79..ac218aeab 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 + DATEADD(week, -1, subq_4.metric_time__day) = 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/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 28159c151..018f4f4d9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(week, -1, subq_19.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql index c6bfc372c..4c8364ec4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATEADD(week, -1, 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 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/Snowflake/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 1e3460920..3e5304e11 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATEADD(week, -1, time_spine_src_28006.ds) = 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/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql index 863715858..9220f0cf7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(day, -14, subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, 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/Snowflake/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0_optimized.sql index bc37fe731..d05ce796b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -14, subq_22.ds) = subq_20.booking__ds__day + DATEADD(day, -14, 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/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql index 131df5613..d9860cc30 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(day, -5, subq_2.metric_time__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 + DATEADD(day, -5, subq_4.metric_time__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/Snowflake/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index ca27d7702..9e7c4ff45 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -5, subq_12.ds) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + DATEADD(day, -5, time_spine_src_28006.ds) = 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_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index c2f529376..f77f413eb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('day', -2, subq_5.metric_time__day) = subq_4.metric_time__day - ) subq_7 - WHERE subq_7.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' - ) subq_8 - ) subq_9 + DATE_ADD('day', -2, subq_7.metric_time__day) = subq_4.metric_time__day + ) subq_8 + WHERE subq_8.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '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/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index c74bc63f1..e3963f89f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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) > DATE_ADD('day', -2, subq_15.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATE_ADD('day', -2, subq_16.ds) ) - ) subq_16 + ) subq_17 ON - DATE_ADD('day', -2, subq_18.ds) = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' + DATE_ADD('day', -2, time_spine_src_28006.ds) = subq_17.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN timestamp '2019-12-19' AND timestamp '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/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 782826cc2..86337ecba 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('month', -1, subq_2.metric_time__month) = subq_1.metric_time__month - ) subq_4 - ) subq_5 + DATE_ADD('month', -1, subq_4.metric_time__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/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 7a98c4a7d..276368a24 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('month', -1, subq_10.metric_time__month) = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + DATE_ADD('month', -1, subq_13.metric_time__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/Trino/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql index 252cd8290..511b7c6ef 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index 7c14527ad..420d8ac04 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 25ee9554a..50403bd89 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 20579c629..5cf1cb51b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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/Trino/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql index 92809b655..8d3e6cb0e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_ADD('day', -14, 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/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql index 97562a5c6..d64a1c891 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day + DATE_ADD('day', -14, 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/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 55707852f..41e01022a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_ADD('day', -14, subq_9.metric_time__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/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index a92f24882..92b999342 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = 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/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 07820dc20..67fa1029c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 - DATE_ADD('month', -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_ADD('month', -1, subq_13.metric_time__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_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index 320c34869..e04652fa8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('month', -1, subq_28.ds) = subq_26.metric_time__day + DATE_ADD('month', -1, time_spine_src_28006.ds) = 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/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 1388092eb..226dc4aaf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 - DATE_ADD('month', -1, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_ADD('month', -1, subq_13.metric_time__day) = 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/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 376523e66..ca4be6f1b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('month', -1, subq_28.ds) = subq_26.metric_time__day + DATE_ADD('month', -1, time_spine_src_28006.ds) = 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/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 6cd2eb1c4..b16c7e1b7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_8.metric_time__day) = subq_7.metric_time__day - ) subq_10 + DATE_ADD('day', -14, subq_10.metric_time__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/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index deaef7874..98a41b885 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -14, subq_25.ds) = subq_23.metric_time__day - ) subq_26 + DATE_ADD('day', -14, time_spine_src_28006.ds) = 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/Trino/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql index 6d72a2d18..f1e3f4f3b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('day', -2, subq_5.metric_time__day) = subq_4.metric_time__day - ) subq_7 - ) subq_8 + DATE_ADD('day', -2, subq_7.metric_time__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/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql index c9431a6e5..0838604a6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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) > DATE_ADD('day', -2, subq_14.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATE_ADD('day', -2, subq_15.ds) ) - ) subq_15 + ) subq_16 ON - DATE_ADD('day', -2, subq_17.ds) = subq_15.metric_time__day + DATE_ADD('day', -2, time_spine_src_28006.ds) = 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/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 128caed9b..87076100a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('week', -1, subq_2.booking__ds__day) = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + DATE_ADD('week', -1, subq_4.booking__ds__day) = 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/Trino/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index bf4161748..4cbcf8999 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('week', -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATE_ADD('week', -1, time_spine_src_28006.ds) = 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/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql index 3005aefe0..e1da184c1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('day', -5, 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 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index bb78d05bf..cd55e4b0d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -5, subq_11.ds) = subq_9.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = 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/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 72065e71c..b47f0d4a2 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,77 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('day', -5, subq_4.metric_time__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 - DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATE_ADD('day', -2, subq_12.metric_time__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/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index 8adb624ac..01dab6b8e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -5, subq_17.ds) = subq_15.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = 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 - DATE_ADD('day', -2, subq_24.ds) = subq_22.metric_time__day - ) subq_25 + DATE_ADD('day', -2, time_spine_src_28006.ds) = 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/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index 761d59928..5ef862220 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,47 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 0694bbdbd..3496289cd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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/Trino/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql index 81b96798c..4a30deed4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql @@ -4,39 +4,61 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('day', -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day -) subq_11 + DATE_ADD('day', -2, subq_12.metric_time__day) = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql index 02db30d70..e59300d86 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -5, subq_15.ds) = subq_13.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - DATE_ADD('day', -2, subq_22.ds) = subq_20.metric_time__day -) subq_23 + DATE_ADD('day', -2, time_spine_src_28006.ds) = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql index 2a720cd40..9d45ea8f0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('day', -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 - WHERE subq_11.metric_time__day BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' -) subq_12 + DATE_ADD('day', -2, subq_12.metric_time__day) = subq_9.metric_time__day + ) subq_13 + WHERE subq_13.metric_time__day BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 8bb73428b..b3018cd73 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -5, subq_16.ds) = subq_14.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATE_ADD('day', -2, subq_23.ds) = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' -) subq_25 + DATE_ADD('day', -2, time_spine_src_28006.ds) = subq_24.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13' +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql index c077b8eaf..890d1bbd5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,66 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('day', -5, 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_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day - ) subq_11 + DATE_ADD('day', -2, subq_12.metric_time__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/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql index eda2cec26..38d6d2753 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -5, subq_16.ds) = subq_14.metric_time__day + DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - DATE_ADD('day', -2, subq_23.ds) = subq_21.metric_time__day - ) subq_24 + DATE_ADD('day', -2, time_spine_src_28006.ds) = 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/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 8bbd7d99d..97f377956 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 600f39647..551977838 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql index 3f7983fed..f5b1c831d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index 88c1ed0b7..e59051e4a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql index 47acb13a2..bad58df50 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index 9f5c75d84..f27304c35 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index dd9bb9335..7698997fe 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('week', -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 + DATE_ADD('week', -1, subq_4.metric_time__day) = 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/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index c2acb8801..ee39d6653 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('week', -1, subq_19.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_20 + DATE_ADD('week', -1, time_spine_src_28006.ds) = 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/Trino/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql index 6f337acc8..ecdb5d2ca 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('week', -1, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_ADD('week', -1, 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 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/Trino/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 5111961e5..3eef121b7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('week', -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + DATE_ADD('week', -1, time_spine_src_28006.ds) = 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/Trino/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql index b6d85b7be..d25f34114 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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_ADD('day', -14, subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATE_ADD('day', -14, 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/Trino/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0_optimized.sql index fe12cd0d6..215d49938 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -14, subq_22.ds) = subq_20.booking__ds__day + DATE_ADD('day', -14, 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/Trino/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql index 0b6a48e46..185531ad6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - WHERE subq_4.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' - ) subq_5 - ) subq_6 + DATE_ADD('day', -5, subq_4.metric_time__day) = subq_1.metric_time__day + ) subq_5 + WHERE subq_5.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '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/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index db938122a..dee7544e9 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -5, subq_12.ds) = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02' + DATE_ADD('day', -5, time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN timestamp '2019-12-19' AND timestamp '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/BigQuery/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_fill_nulls__plan0.sql index f1ab433c4..d5c090650 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_fill_nulls__plan0_optimized.sql index ff83eff86..170b5bf10 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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 ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_13.ds + DATETIME_TRUNC(bookings_source_src_28000.ds, day) <= subq_14.ds ) AND ( - DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_13.ds AS DATETIME), INTERVAL 2 day) + DATETIME_TRUNC(bookings_source_src_28000.ds, day) > DATE_SUB(CAST(subq_14.ds AS DATETIME), INTERVAL 2 day) ) GROUP BY metric_time__day - ) subq_16 + ) 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/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 9fb6348b0..2d0012cd4 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_10.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_SUB(CAST(subq_13.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY metric_time__day - ) subq_14 - ) subq_15 + ) 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 metric_time__day -) subq_16 +) subq_18 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 576edf228..8e48b6f85 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_29 ON - DATE_SUB(CAST(subq_28.ds AS DATETIME), INTERVAL 14 day) = subq_26.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = subq_29.metric_time__day GROUP BY metric_time__day - ) subq_32 + ) 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 metric_time__day -) subq_33 +) subq_37 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index f906547d3..edbdec60b 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_6.ds, month) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index 61f5537d6..780968de7 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: BigQuery -- 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 , DATETIME_TRUNC(ds, month) 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 ( , DATETIME_TRUNC(ds, month) 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 3b815691d..2e117ea48 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_6.ds, month) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index e70deef36..200ad9e55 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: BigQuery -- 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 , DATETIME_TRUNC(ds, month) 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 ( , DATETIME_TRUNC(ds, day) 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index e83de302c..364ed5862 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/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: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_6.ds, month) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 95caa9421..71eb59eed 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/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: BigQuery -- 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 , DATETIME_TRUNC(ds, month) 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 ( , DATETIME_TRUNC(ds, day) 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/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index a67b4d9f0..5026646b1 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: BigQuery --- -- 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 - DATETIME_TRUNC(subq_6.ts, day) 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 + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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 metric_time__day - ) subq_5 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -618,5 +640,5 @@ FROM ( 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/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index b069e9ae8..cb1723dff 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: BigQuery -- 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 DATETIME_TRUNC(ts, day) 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 ( , DATETIME_TRUNC(archived_at, day) 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/BigQuery/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__plan0.sql index d33848a09..ab0e79be2 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: BigQuery --- -- 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 - , DATETIME_TRUNC(subq_7.ds, isoweek) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__plan0_optimized.sql index fc1d485a5..09344e164 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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 , DATETIME_TRUNC(ds, isoweek) 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 DATETIME_TRUNC(ds, day) 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/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0.sql index 91d79f154..9d5e32da3 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index 9cd507a22..ef18f2efa 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(ds, day) 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/BigQuery/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_month__plan0.sql index 1a838af28..b5762cfa7 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: BigQuery --- -- 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 - DATETIME_TRUNC(subq_5.ds, month) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 metric_time__month - ) subq_4 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -229,5 +251,5 @@ FROM ( 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/BigQuery/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index 003a95adb..25cebb792 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/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 DATETIME_TRUNC(ds, month) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY metric_time__month - ) subq_11 + ) subq_14 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -32,10 +34,10 @@ FROM ( DATETIME_TRUNC(ds, month) 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_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0.sql index 329939234..8473d26b7 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0_optimized.sql index f402f4015..f00599459 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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) > DATEADD(day, -2, subq_13.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_14.ds) ) 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/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql index ff700c798..457f4071d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(day, -14, subq_13.metric_time__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/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index ba9e282ec..c21c69532 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -14, subq_28.ds) = subq_26.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index 4370282ae..1fe8f50cb 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index 2282acd20..015fa2127 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: Databricks -- 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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 5356e3397..c11a194d4 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index d9f5ff926..16a9cfd0b 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: Databricks -- 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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index 73f9eb22d..556cd50cf 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/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: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 43db70157..9fad967f9 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/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: Databricks -- 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/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index 8346be424..76d167153 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/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/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index 304c800e4..734a97a23 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: Databricks -- 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/Databricks/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__plan0.sql index f1d349a80..94346b1be 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__plan0_optimized.sql index 74c708c8e..9fe01abde 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0.sql index f2efd2d72..c67a0a2e9 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index 179c2b34b..94ff4a457 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_month__plan0.sql index 9d861ff6e..49a07628d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index dedc11ff7..903e89a6d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/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_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0.sql index 06958d27b..052c50251 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Postgres --- -- 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/Postgres/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0_optimized.sql index 4881dd460..40347e593 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 2) + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.ds - MAKE_INTERVAL(days => 2) ) 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/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql index d39655e2e..e803d95af 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 14) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 44671f824..3647fb8fd 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 14) = subq_26.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index 6e0794f61..c28fe516e 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Postgres --- -- 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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index b4ad638e3..d92e57f3e 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: Postgres -- 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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 529aff654..61ac71498 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: Postgres --- -- 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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index 82aa6ba37..6d860edf7 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: Postgres -- 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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index a08ad2821..02b86a76d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/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: Postgres --- -- 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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 010c92bf2..7a1a8ef68 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/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: Postgres -- 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/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index c304a7cbe..378849d5b 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: Postgres --- -- 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/Postgres/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/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index b305cd0dc..9522db4e2 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: Postgres -- 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/Postgres/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__plan0.sql index b6e2a39be..f3539ad1a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: Postgres --- -- 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/Postgres/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__plan0_optimized.sql index 1aa6ec229..8038d1340 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0.sql index ee610ec2e..0fdde58cd 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Postgres --- -- 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/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index e5ad631c9..8ecb135bd 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_month__plan0.sql index 14cd08fdd..e08f96c33 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: Postgres --- -- 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/Postgres/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index 7b2e9d7b6..bf2b71823 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/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_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0.sql index f5848192b..428122840 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0_optimized.sql index cff38d699..228808005 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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) > DATEADD(day, -2, subq_13.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_14.ds) ) 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/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 07a40daab..b75d08b2c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(day, -14, subq_13.metric_time__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/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 25e33fd18..71aab401e 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -14, subq_28.ds) = subq_26.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index 8774fd78d..a51cb2534 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index 0bf3b2907..bfa923a39 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: Redshift -- 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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 121b170ef..edae3b8d2 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index 05d5c2c08..29dd3c545 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: Redshift -- 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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index 9285d0f17..149ad4a8c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/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: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 13d7ad5eb..59b9ec778 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/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: Redshift -- 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/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index c49a223f6..b99fdd742 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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/Redshift/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/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index bf3835d2b..9b8badbb9 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: Redshift -- 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/Redshift/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filters__plan0.sql index 9f9bde759..79b072f18 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filters__plan0_optimized.sql index 9b9bd45b7..49adb5a8c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0.sql index 7a79937fa..5c2844da6 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index 98fb58c9c..36fc75aa1 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_month__plan0.sql index 737a0e933..1d157eb6e 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index c66e45650..28a1cbce3 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/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_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0.sql index b940e505e..6ab4f792d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0_optimized.sql index 3fc6b83ac..86bc959f0 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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) > DATEADD(day, -2, subq_13.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATEADD(day, -2, subq_14.ds) ) 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/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql index aacf95618..066275fdc 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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(dayofweekiso 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 - DATEADD(day, -14, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATEADD(day, -14, subq_13.metric_time__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/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 34a698d3f..24cd1192e 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -14, subq_28.ds) = subq_26.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index e911843e2..786f1d06c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index c3fbedd6a..e693dcac8 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: Snowflake -- 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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index dfe62f1d8..9f82c13a5 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index 8e361ce9c..f80047dcf 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: Snowflake -- 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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index 79e86b272..98dccdec7 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/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: Snowflake --- -- 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(dayofweekiso 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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 10f573e60..df83ffd2c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/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: Snowflake -- 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/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index e71ef8663..2e734c276 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index 7cc83fd88..d61836100 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: Snowflake -- 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/Snowflake/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filters__plan0.sql index 8834fd78c..a5a0dcbf6 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filters__plan0_optimized.sql index e943c194d..7eeca32ba 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0.sql index e52e911b8..cc02c61ba 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index c1e9df528..812595810 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_month__plan0.sql index 996ab626d..cbc6d0320 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index 6f302a497..b0f3f53f3 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/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_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql index a96adb97e..e83b8ee88 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql index 4d68df91c..a737bf833 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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) > DATE_ADD('day', -2, subq_13.ds) + DATE_TRUNC('day', bookings_source_src_28000.ds) > DATE_ADD('day', -2, subq_14.ds) ) 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/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 812cafa17..51fadf689 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_10.metric_time__day) = subq_9.metric_time__day - ) subq_12 - ) subq_13 + DATE_ADD('day', -14, subq_13.metric_time__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/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 45f332582..bab6cbd6a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -14, subq_28.ds) = subq_26.metric_time__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = 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/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index 054ccef04..0c5fe4c9d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,52 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index 3dc708c76..152ff7343 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: Trino -- 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/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 9a183f5ef..513f3fe44 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,54 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index 30f440d3c..72bb8efe6 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: Trino -- 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/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index 0e51c11f9..cf8809654 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/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: Trino --- -- 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(DAY_OF_WEEK 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/Trino/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/Trino/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index d99e51e0f..274e58e86 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/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: Trino -- 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/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index 0d0d47818..f4f622471 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,54 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/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/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index 3fc203f8d..879d15f26 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: Trino -- 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/Trino/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0.sql index 3d8dc1801..72541bb03 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,66 @@ sql_engine: Trino --- -- 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 timestamp '2020-01-03' AND timestamp '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(DAY_OF_WEEK 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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '2020-01-05' -) subq_10 + subq_10.metric_time__day = subq_5.metric_time__day + ) subq_11 + WHERE subq_11.metric_time__day BETWEEN timestamp '2020-01-03' AND timestamp '2020-01-05' +) subq_12 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0_optimized.sql index 588e8f1d1..4516d044a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '2020-01-05' -) subq_21 + subq_23.metric_time__day = subq_18.metric_time__day + WHERE subq_23.metric_time__day BETWEEN timestamp '2020-01-03' AND timestamp '2020-01-05' +) subq_25 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql index e2adfda22..8509517a1 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index 1d62fa0a8..64a16a330 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/Trino/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql index 40c87b43f..f727a5751 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,43 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index bf59616d7..981ca0829 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/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/BigQuery/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql index a505a2032..84cef61fe 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: BigQuery --- -- 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 - , IF(EXTRACT(dayofweek FROM subq_8.ds) = 1, 7, EXTRACT(dayofweek FROM subq_8.ds) - 1) 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_7.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_SUB(CAST(subq_9.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY metric_time__extract_dow - ) subq_11 - ) subq_12 + ) 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 metric_time__extract_dow -) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0_optimized.sql index 6aad32a7f..0e8ba946f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/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 ( IF(EXTRACT(dayofweek FROM ds) = 1, 7, EXTRACT(dayofweek FROM ds) - 1) 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 - IF(EXTRACT(dayofweek FROM subq_22.ds) = 1, 7, EXTRACT(dayofweek FROM subq_22.ds) - 1) AS metric_time__extract_dow - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) 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 ( DATETIME_TRUNC(ds, day) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_21 ON - DATE_SUB(CAST(subq_22.ds AS DATETIME), INTERVAL 14 day) = subq_20.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = subq_21.metric_time__day GROUP BY metric_time__extract_dow - ) subq_26 + ) 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 metric_time__extract_dow -) subq_27 +) subq_29 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0.sql index 526a223b4..f0e2100f1 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATETIME_TRUNC(time_spine_src_28002.ts, millisecond) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATETIME_TRUNC(time_spine_src_28002.ts, second) AS ts__second , DATETIME_TRUNC(time_spine_src_28002.ts, minute) AS ts__minute , DATETIME_TRUNC(time_spine_src_28002.ts, hour) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0_optimized.sql index 5afa70585..01adc93d6 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: BigQuery -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATETIME_TRUNC(ts, millisecond) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY metric_time__millisecond diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index 6c1dc6ea5..532af83b4 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index f1ce4bf13..9780279b2 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: BigQuery -- 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 ( DATETIME_TRUNC(archived_at, hour) 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/BigQuery/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0.sql index 4e7932a2d..7ed08c982 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index 96e2502fd..afb11ecd8 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: BigQuery -- 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 ( DATETIME_TRUNC(archived_at, hour) 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/BigQuery/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0.sql index 8a5c56845..3e1c9a87a 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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 - DATETIME_TRUNC(subq_2.metric_time__hour, hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATETIME_TRUNC(subq_4.metric_time__hour, hour) = subq_1.metric_time__hour + ) subq_5 + ) subq_6 GROUP BY metric_time__hour - ) subq_6 -) subq_7 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index 5a9219415..bedcf0999 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(archived_at, hour) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 ON - DATETIME_TRUNC(subq_11.ts, hour) = subq_9.metric_time__hour + DATETIME_TRUNC(time_spine_src_28005.ts, hour) = subq_10.metric_time__hour GROUP BY metric_time__hour -) subq_15 +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0.sql index 4f79f08a2..077be5964 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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_SUB(CAST(subq_2.metric_time__hour AS DATETIME), INTERVAL 1 hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATE_SUB(CAST(subq_4.metric_time__hour AS DATETIME), INTERVAL 1 hour) = subq_1.metric_time__hour + ) subq_5 + ) subq_6 GROUP BY metric_time__hour - ) subq_6 -) subq_7 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0_optimized.sql index 7997b120d..9a21c21fe 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/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 ( DATETIME_TRUNC(archived_at, hour) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 ON - DATE_SUB(CAST(subq_11.ts AS DATETIME), INTERVAL 1 hour) = subq_9.metric_time__hour + DATE_SUB(CAST(time_spine_src_28005.ts AS DATETIME), INTERVAL 1 hour) = subq_10.metric_time__hour GROUP BY metric_time__hour -) subq_15 +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0.sql index b2926769d..0775cc218 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28005.ts, day) AS ts__day + , DATETIME_TRUNC(time_spine_src_28005.ts, isoweek) AS ts__week + , DATETIME_TRUNC(time_spine_src_28005.ts, month) AS ts__month + , DATETIME_TRUNC(time_spine_src_28005.ts, quarter) AS ts__quarter + , DATETIME_TRUNC(time_spine_src_28005.ts, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28005.ts) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28005.ts) - 1) AS ts__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index 49cdb09ec..514d9cbbc 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: BigQuery -- 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 DATETIME_TRUNC(archived_at, hour) 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_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0.sql index 76ab641df..d23120a10 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATETIME_TRUNC(time_spine_src_28003.ts, second) AS ts__second + time_spine_src_28003.ts AS ts__second , DATETIME_TRUNC(time_spine_src_28003.ts, minute) AS ts__minute , DATETIME_TRUNC(time_spine_src_28003.ts, hour) AS ts__hour , DATETIME_TRUNC(time_spine_src_28003.ts, day) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index bb805e7bb..ce7057102 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: BigQuery -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATETIME_TRUNC(ts, second) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATETIME_TRUNC(ts, second) BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' +WHERE ts BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' GROUP BY metric_time__second diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql index 78e5a822a..3303dd979 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Databricks/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0_optimized.sql index fcbbcc1ba..5b86d8479 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - EXTRACT(DAYOFWEEK_ISO FROM subq_22.ds) - ) subq_26 + EXTRACT(DAYOFWEEK_ISO 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/Databricks/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0.sql index 741feb683..72f044094 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0_optimized.sql index c630b8c5d..c9967312a 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Databricks -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATE_TRUNC('millisecond', ts) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY - DATE_TRUNC('millisecond', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index 6f285dc40..cd2572478 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index d0280d8ec..5f3731d46 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Databricks -- 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/Databricks/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0.sql index 031c035f9..42b2dd4e1 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index 95cde0677..cad51c672 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Databricks -- 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/Databricks/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_to_grain_metric__plan0.sql index cea3e05ee..1b3200217 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index a2be431b3..45d51ea23 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_window_metric__plan0.sql index be705a33d..b2f7fd8b0 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(hour, -1, subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATEADD(hour, -1, 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/Databricks/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_window_metric__plan0_optimized.sql index 33ac7b7e6..7c292f8d4 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(hour, -1, subq_11.ts) = subq_9.metric_time__hour + DATEADD(hour, -1, 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/Databricks/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0.sql index 037d6a95e..301f1659c 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index dfce633ca..18f5a4f4a 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: Databricks -- 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_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0.sql index 072d4be07..fae663a8c 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second + time_spine_src_28003.ts AS ts__second , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index c84265d19..dbfb173c1 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: Databricks -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATE_TRUNC('second', ts) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATE_TRUNC('second', ts) BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' +WHERE ts BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' GROUP BY - DATE_TRUNC('second', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql index 6d998a8f5..eb97d4d7a 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 14) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0_optimized.sql index 5e0bf2bbc..4aef7d64a 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 14) = subq_20.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0.sql index 42256c457..7d548d677 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0_optimized.sql index 3a7db9be7..1b241ced5 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Postgres -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATE_TRUNC('millisecond', ts) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY - DATE_TRUNC('millisecond', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index d066a3acb..c587f4779 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Postgres --- -- 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/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index 07c19ae30..36cb00d7d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Postgres -- 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/Postgres/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0.sql index 4c9f57d85..097eaf962 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Postgres --- -- 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/Postgres/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index e4ddf574a..86db1791d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Postgres -- 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/Postgres/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_to_grain_metric__plan0.sql index 01c5d362a..d28e2a7cd 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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/Postgres/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index 4ebee052c..4393ab1af 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_window_metric__plan0.sql index 7423e9cec..3bb4eeb2f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(hours => 1) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + subq_4.metric_time__hour - MAKE_INTERVAL(hours => 1) = 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/Postgres/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_window_metric__plan0_optimized.sql index 41dd8e327..7975949ef 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(hours => 1) = subq_9.metric_time__hour + time_spine_src_28005.ts - MAKE_INTERVAL(hours => 1) = 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/Postgres/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0.sql index e47857efa..578bfb625 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: Postgres --- -- 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/Postgres/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index db2603787..325abee03 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: Postgres -- 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_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0.sql index c24d95610..e9c10cfcb 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second + time_spine_src_28003.ts AS ts__second , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index f7e83dfc4..dff63d8de 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: Postgres -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATE_TRUNC('second', ts) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATE_TRUNC('second', ts) BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' +WHERE ts BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' GROUP BY - DATE_TRUNC('second', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql index ebc94261b..6889b3d30 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Redshift --- -- 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 - , CASE WHEN EXTRACT(dow FROM subq_8.ds) = 0 THEN EXTRACT(dow FROM subq_8.ds) + 7 ELSE EXTRACT(dow FROM subq_8.ds) END 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Redshift/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0_optimized.sql index c2b638224..fa2348d83 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/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 ( CASE WHEN EXTRACT(dow FROM ds) = 0 THEN EXTRACT(dow FROM ds) + 7 ELSE EXTRACT(dow FROM ds) END 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 - CASE WHEN EXTRACT(dow FROM subq_22.ds) = 0 THEN EXTRACT(dow FROM subq_22.ds) + 7 ELSE EXTRACT(dow FROM subq_22.ds) END AS metric_time__extract_dow - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - CASE WHEN EXTRACT(dow FROM subq_22.ds) = 0 THEN EXTRACT(dow FROM subq_22.ds) + 7 ELSE EXTRACT(dow FROM subq_22.ds) END - ) subq_26 + CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END + ) 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/Redshift/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0.sql index 70ee6f110..8d45cb78d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0_optimized.sql index 0390430b2..fb84f3325 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Redshift -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATE_TRUNC('millisecond', ts) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY - DATE_TRUNC('millisecond', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index f0c40272e..d85116362 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index 453237b4f..6c82bf533 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Redshift -- 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/Redshift/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0.sql index 54b24c63a..1d75d1489 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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/Redshift/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index 0c0b432a2..602052f02 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Redshift -- 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/Redshift/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_to_grain_metric__plan0.sql index 1ffc9288b..7a4b358de 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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/Redshift/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index 7b1ea188a..8e7fb780f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_window_metric__plan0.sql index dec0c1f26..3e6befa2c 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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 - DATEADD(hour, -1, subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATEADD(hour, -1, 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/Redshift/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_window_metric__plan0_optimized.sql index eeb440b35..94c485ec0 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(hour, -1, subq_11.ts) = subq_9.metric_time__hour + DATEADD(hour, -1, 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/Redshift/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0.sql index 720f5b5fc..22a3fe7e6 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28005.ts) = 0 THEN EXTRACT(dow FROM time_spine_src_28005.ts) + 7 ELSE EXTRACT(dow FROM time_spine_src_28005.ts) END 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/Redshift/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index ea228e49a..0fb64ca19 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: Redshift -- 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_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0.sql index 83e45cba5..60c9294d3 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second + time_spine_src_28003.ts AS ts__second , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index 8d5f22e9a..0ce2906c6 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: Redshift -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATE_TRUNC('second', ts) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATE_TRUNC('second', ts) BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' +WHERE ts BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' GROUP BY - DATE_TRUNC('second', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql index 4bf8aa2ad..613e8b939 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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(dayofweekiso 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 - DATEADD(day, -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATEADD(day, -14, subq_9.metric_time__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/Snowflake/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0_optimized.sql index 656edaf9f..cc38a3b19 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/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(dayofweekiso 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(dayofweekiso 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(dayofweekiso 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 - DATEADD(day, -14, subq_22.ds) = subq_20.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - EXTRACT(dayofweekiso FROM subq_22.ds) - ) subq_26 + EXTRACT(dayofweekiso 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/Snowflake/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0.sql index f04969898..a60843bb7 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0_optimized.sql index 4115c3557..9ea914683 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Snowflake -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATE_TRUNC('millisecond', ts) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY - DATE_TRUNC('millisecond', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index f49b63940..fa5860a89 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index 2eeeed0e1..bfd447c99 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Snowflake -- 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/Snowflake/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0.sql index 886780f3c..1944ca5da 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index df5043613..5364ec057 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Snowflake -- 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/Snowflake/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_to_grain_metric__plan0.sql index 40a67cce5..4f56de7eb 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index 0ac8b2525..c6434d88b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_window_metric__plan0.sql index eb88be742..d9076f1ce 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(hour, -1, subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATEADD(hour, -1, 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/Snowflake/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_window_metric__plan0_optimized.sql index 0ee8b61db..ec5df2185 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(hour, -1, subq_11.ts) = subq_9.metric_time__hour + DATEADD(hour, -1, 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/Snowflake/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0.sql index e4a514167..86c83e484 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index bfbc3f9e2..4c2276419 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: Snowflake -- 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_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0.sql index 6dae54466..01f30c25f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second + time_spine_src_28003.ts AS ts__second , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index ae3580bbd..d485ef703 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: Snowflake -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATE_TRUNC('second', ts) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATE_TRUNC('second', ts) BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' +WHERE ts BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' GROUP BY - DATE_TRUNC('second', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql index 86d96b5a5..5ab1a267b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_ADD('day', -14, subq_9.metric_time__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/Trino/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql index 4def88a76..799bee05d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/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(DAY_OF_WEEK 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = subq_21.metric_time__day GROUP BY - EXTRACT(DAY_OF_WEEK FROM subq_22.ds) - ) subq_26 + EXTRACT(DAY_OF_WEEK 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/Trino/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0.sql index 20b53144b..adccf749f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0.sql @@ -41,7 +41,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_millisecond' SELECT - DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond + time_spine_src_28002.ts AS ts__millisecond , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0_optimized.sql index b246c4a22..01cc5609f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_sub_daily_metric_time__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Trino -- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - DATE_TRUNC('millisecond', ts) AS metric_time__millisecond + ts AS metric_time__millisecond FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 GROUP BY - DATE_TRUNC('millisecond', ts) + ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index e64167221..6fa13ae01 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index 5a6cc1257..085d354e2 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Trino -- 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/Trino/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0.sql index f0e67cd86..79955d227 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index ab20d4c19..1638287ee 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Trino -- 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/Trino/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_to_grain_metric__plan0.sql index d5e95786d..8b019179d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index 6eca0ddc3..b47f0d671 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/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/Trino/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_window_metric__plan0.sql index fd5a04343..2785ad709 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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_ADD('hour', -1, subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATE_ADD('hour', -1, 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/Trino/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_window_metric__plan0_optimized.sql index f51d27ebe..cdf9770cc 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('hour', -1, subq_11.ts) = subq_9.metric_time__hour + DATE_ADD('hour', -1, 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/Trino/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0.sql index aab4b84e7..1bd23705a 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,53 @@ sql_engine: Trino --- -- 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 timestamp '2020-01-01 02:00:00' AND timestamp '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(DAY_OF_WEEK 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 timestamp '2020-01-01 02:00:00' AND timestamp '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 timestamp '2020-01-01 02:00:00' AND timestamp '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 timestamp '2020-01-01 02:00:00' AND timestamp '2020-01-01 05:00:00' +) subq_10 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index 3b87095ae..0d406c1d6 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: Trino -- 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 timestamp '2020-01-01 02:00:00' AND timestamp '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 timestamp '2020-01-01 02:00:00' AND timestamp '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 timestamp '2020-01-01 02:00:00' AND timestamp '2020-01-01 05:00:00' + subq_19.metric_time__hour = subq_15.metric_time__hour +WHERE subq_19.metric_time__hour BETWEEN timestamp '2020-01-01 02:00:00' AND timestamp '2020-01-01 05:00:00' diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0.sql index 0ad00d294..7075b2156 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -70,7 +70,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine_second' SELECT - DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second + time_spine_src_28003.ts AS ts__second , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql index 6a8c7968f..0edc9ed91 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_subdaily_time_constraint_without_metrics__plan0_optimized.sql @@ -7,8 +7,8 @@ sql_engine: Trino -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - DATE_TRUNC('second', ts) AS metric_time__second + ts AS metric_time__second FROM ***************************.mf_time_spine_second time_spine_src_28003 -WHERE DATE_TRUNC('second', ts) BETWEEN timestamp '2020-01-01 00:00:02' AND timestamp '2020-01-01 00:00:08' +WHERE ts BETWEEN timestamp '2020-01-01 00:00:02' AND timestamp '2020-01-01 00:00:08' GROUP BY - DATE_TRUNC('second', ts) + ts diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0.sql index dd9c991ac..204fa0945 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0_optimized.sql index 6d88dc1f1..f6afbb3b9 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: BigQuery -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,7 +16,7 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATETIME_TRUNC(time_spine_src_28006.ds, day) BETWEEN '2020-01-01' AND '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN '2020-01-01' AND '2020-01-03' GROUP BY metric_time__day , listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0.sql index 03f1e60d7..db2e1ba1e 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0_optimized.sql index a28135efb..9c583cd36 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: BigQuery -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATETIME_TRUNC(ds, day) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_quarter_alone__plan0.sql index 1e36bab5d..8f232846b 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0.sql index d417da1fa..7763a36b2 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0_optimized.sql index a812644fa..2087e24eb 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/BigQuery/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: BigQuery -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0.sql index 13d7fa7ff..f67b139ba 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0_optimized.sql index 2cf42ce5d..6d943cc04 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Databricks -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,8 +16,8 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN '2020-01-01' AND '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN '2020-01-01' AND '2020-01-03' GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0.sql index 752986b2d..df27d3f1c 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0_optimized.sql index 233227bf1..561074791 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: Databricks -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_quarter_alone__plan0.sql index 60cb8f349..88745af88 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0.sql index f3a1bdc2d..a8a94d849 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0_optimized.sql index 9adb12669..b2c876e43 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Databricks/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: Databricks -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,6 +16,6 @@ FULL OUTER JOIN ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0.sql index 9a32af410..d2d6325ae 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0_optimized.sql index 3ab1c2cd7..421b597cb 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Postgres -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,8 +16,8 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN '2020-01-01' AND '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN '2020-01-01' AND '2020-01-03' GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0.sql index 9e6c0f439..5dac36939 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0_optimized.sql index d30aeb8ce..ceee9d957 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: Postgres -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_quarter_alone__plan0.sql index 02a2fbe20..34046690b 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0.sql index 82e33f4b0..e79d804b4 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0_optimized.sql index 63d1ce8f6..248ec8ab1 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Postgres/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: Postgres -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,6 +16,6 @@ FULL OUTER JOIN ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0.sql index 86ad34143..5ca4d4e68 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0_optimized.sql index f0c7b115c..c656e87b2 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Redshift -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,8 +16,8 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN '2020-01-01' AND '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN '2020-01-01' AND '2020-01-03' GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0.sql index 9a16e4019..196f557ba 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0_optimized.sql index 35ee89b9e..716a39e7b 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: Redshift -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_quarter_alone__plan0.sql index b6be7d7c0..fbdba485b 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0.sql index 48588917e..6c1d35895 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0_optimized.sql index 449918ddd..096ee1c6c 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Redshift/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: Redshift -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,6 +16,6 @@ FULL OUTER JOIN ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0.sql index 4892a897b..b64d5e9eb 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0_optimized.sql index f61217729..4cba1e7f8 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Snowflake -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,8 +16,8 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN '2020-01-01' AND '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN '2020-01-01' AND '2020-01-03' GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0.sql index ff8ad8419..3f15fa642 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0_optimized.sql index edff68d5e..0fb73d204 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: Snowflake -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_quarter_alone__plan0.sql index d9ea85e51..13fa2c885 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0.sql index e6303f3ba..ef0c2368a 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0_optimized.sql index 8cc860f7f..22ed9e9e6 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Snowflake/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: Snowflake -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,6 +16,6 @@ FULL OUTER JOIN ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0.sql index 1323d82a3..49e96f2dd 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0.sql @@ -224,7 +224,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0_optimized.sql index 63ccc44d0..682daba14 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_dimensions_with_time_constraint__plan0_optimized.sql @@ -6,7 +6,7 @@ sql_engine: Trino -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,8 +16,8 @@ FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -WHERE DATE_TRUNC('day', time_spine_src_28006.ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-03' +WHERE time_spine_src_28006.ds BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-03' GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0.sql index f93f9fda8..dcdcb6c78 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0.sql @@ -37,7 +37,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0_optimized.sql index 1a2575775..9df66baf6 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_only__plan0_optimized.sql @@ -8,7 +8,7 @@ sql_engine: Trino -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_quarter_alone__plan0.sql index b17fa8e91..bbe069fe2 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_quarter_alone__plan0.sql @@ -35,7 +35,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0.sql index 54cbee6aa..ab7805e1e 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0.sql @@ -163,7 +163,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0_optimized.sql index 43d59ec97..3a295e45c 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/Trino/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -5,7 +5,7 @@ sql_engine: Trino -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 @@ -16,6 +16,6 @@ FULL OUTER JOIN ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY - DATE_TRUNC('day', time_spine_src_28006.ds) + time_spine_src_28006.ds , listings_latest_src_28000.is_lux , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index e3720fbdc..973599f5d 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( , 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_15.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_14.metric_time__day - ) subq_17 + DATE_SUB(CAST(subq_18.metric_time__day AS DATETIME), 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 metric_time__day , listing__country_latest - ) subq_24 + ) 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 metric_time__day , listing__country_latest -) subq_29 +) subq_32 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index c0df4693c..5eb586230 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/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 - DATE_SUB(CAST(subq_46.ds AS DATETIME), INTERVAL 14 day) = subq_44.metric_time__day - ) subq_47 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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 metric_time__day , listing__country_latest -) subq_59 +) subq_65 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0.sql index 61b8e67df..9671757b6 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 - DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), INTERVAL 14 day) = subq_11.metric_time__day - ) subq_14 + DATE_SUB(CAST(subq_14.metric_time__day AS DATETIME), 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 metric_time__day , listing__country_latest - ) subq_21 - ) subq_22 + ) 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 metric_time__day , listing__country_latest -) subq_23 +) subq_24 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 649c63350..66680a7f0 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/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 - DATE_SUB(CAST(subq_37.ds AS DATETIME), INTERVAL 14 day) = subq_35.metric_time__day - ) subq_38 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), 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 metric_time__day , listing__country_latest -) subq_47 +) subq_49 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index 216c2ec20..6c5ef49c4 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( , 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/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index 2659e82a7..9c9080de2 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/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_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index f8a742f6d..19f2a852c 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_15.metric_time__day) = subq_14.metric_time__day - ) subq_17 + DATEADD(day, -14, subq_18.metric_time__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/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 9daa5092a..9585dfe01 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -14, subq_46.ds) = subq_44.metric_time__day - ) subq_47 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Databricks/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_offset_metric_with_query_time_filters__plan0.sql index b13b34da5..936b1c6d1 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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 - DATEADD(day, -14, subq_12.metric_time__day) = subq_11.metric_time__day - ) subq_14 + DATEADD(day, -14, subq_14.metric_time__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/Databricks/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 3916fbc8d..7d1e8f030 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/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 - DATEADD(day, -14, subq_37.ds) = subq_35.metric_time__day - ) subq_38 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index 95474dc02..0e4d63bd0 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index 7d1ca9d50..241b0cd73 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/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_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index 45d622783..77dbbe738 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 14) = subq_14.metric_time__day - ) subq_17 + subq_18.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 15ac247a9..89a854384 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 14) = subq_44.metric_time__day - ) subq_47 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_offset_metric_with_query_time_filters__plan0.sql index e2943612f..eacf482d1 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: Postgres --- -- 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 - MAKE_INTERVAL(days => 14) = subq_11.metric_time__day - ) subq_14 + subq_14.metric_time__day - MAKE_INTERVAL(days => 14) = 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/Postgres/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 637b25a3f..e1b2db56d 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/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 - MAKE_INTERVAL(days => 14) = subq_35.metric_time__day - ) subq_38 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = 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/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index d357c66ea..753078dbd 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: Postgres --- -- 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/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index 8b30ca56e..52dd1020a 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/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_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index 5cd70913b..cf718556e 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_15.metric_time__day) = subq_14.metric_time__day - ) subq_17 + DATEADD(day, -14, subq_18.metric_time__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/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 26fd818dd..419a35173 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -14, subq_46.ds) = subq_44.metric_time__day - ) subq_47 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Redshift/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_offset_metric_with_query_time_filters__plan0.sql index 86c4b97d3..0a3a244b8 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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 - DATEADD(day, -14, subq_12.metric_time__day) = subq_11.metric_time__day - ) subq_14 + DATEADD(day, -14, subq_14.metric_time__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/Redshift/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 360555b7c..f821dafef 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/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 - DATEADD(day, -14, subq_37.ds) = subq_35.metric_time__day - ) subq_38 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index 1389f1d89..9c34bb6af 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index 0e86ce90f..c893fefbc 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/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_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index 06d700d00..b445df375 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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(dayofweekiso 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(dayofweekiso 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 - DATEADD(day, -14, subq_15.metric_time__day) = subq_14.metric_time__day - ) subq_17 + DATEADD(day, -14, subq_18.metric_time__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/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 0910734c3..bbd2a1ba2 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -14, subq_46.ds) = subq_44.metric_time__day - ) subq_47 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Snowflake/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_offset_metric_with_query_time_filters__plan0.sql index 58096f0e8..9831db573 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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 - DATEADD(day, -14, subq_12.metric_time__day) = subq_11.metric_time__day - ) subq_14 + DATEADD(day, -14, subq_14.metric_time__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/Snowflake/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 0fbcd96ac..a8b170c4f 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/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 - DATEADD(day, -14, subq_37.ds) = subq_35.metric_time__day - ) subq_38 + DATEADD(day, -14, time_spine_src_28006.ds) = 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/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index 8af26b0e9..f2e9ea2b9 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index 9abfe0b08..b9adcba9f 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/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_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index f43548aff..fe4df3051 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,56 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_15.metric_time__day) = subq_14.metric_time__day - ) subq_17 + DATE_ADD('day', -14, subq_18.metric_time__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/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index 0a8042dc5..332fb030e 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -14, subq_46.ds) = subq_44.metric_time__day - ) subq_47 + DATE_ADD('day', -14, time_spine_src_28006.ds) = 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/Trino/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_offset_metric_with_query_time_filters__plan0.sql index a0e2d67c1..ccfb347e5 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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 - DATE_ADD('day', -14, subq_12.metric_time__day) = subq_11.metric_time__day - ) subq_14 + DATE_ADD('day', -14, subq_14.metric_time__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/Trino/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_offset_metric_with_query_time_filters__plan0_optimized.sql index 2187c0708..4a8cf474a 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/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 - DATE_ADD('day', -14, subq_37.ds) = subq_35.metric_time__day - ) subq_38 + DATE_ADD('day', -14, time_spine_src_28006.ds) = 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/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index aeb65f982..2da638870 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,49 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index cc5b200f4..acd93ba33 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/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_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0.sql index e63da94ce..c5a238d46 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0_optimized.sql index f067853ff..880ab8b58 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time__plan0_optimized.sql @@ -13,7 +13,7 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATETIME_TRUNC(ds, day) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time_week__plan0.sql index 0a3b4a087..99fb54f88 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATETIME_TRUNC(time_spine_src_28006.ds, day) AS ds__day + time_spine_src_28006.ds AS ds__day , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0.sql index fbc7d58b0..68327fbec 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0_optimized.sql index 8dd1eb2e9..ed8ed107b 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time__plan0_optimized.sql @@ -13,8 +13,8 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds ) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time_week__plan0.sql index f3b44dc14..7b4f92711 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0.sql index 4bc028bcb..41e1db11d 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0_optimized.sql index 13f1bc8b9..e0c32113f 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time__plan0_optimized.sql @@ -13,8 +13,8 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds ) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time_week__plan0.sql index c6fef2e1e..6144d5b14 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0.sql index 1e33d2184..f03cc14a7 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0_optimized.sql index 6563a305b..830a7f9a4 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time__plan0_optimized.sql @@ -13,8 +13,8 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds ) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time_week__plan0.sql index a17846030..709be0898 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0.sql index 4d6e8b283..d4cebb1bf 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0_optimized.sql index 70404201b..4eccdb3cf 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time__plan0_optimized.sql @@ -13,8 +13,8 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds ) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time_week__plan0.sql index 09ba241b3..e14f87776 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0.sql index 2492a9693..ee9846830 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0_optimized.sql index 5e802093d..9d4a93b54 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time__plan0_optimized.sql @@ -13,8 +13,8 @@ FROM ( -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - DATE_TRUNC('day', ds) AS metric_time__day + ds AS metric_time__day FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY - DATE_TRUNC('day', ds) + ds ) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time_week__plan0.sql index 89e34683d..296bb6b2d 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_min_max_metric_time_week__plan0.sql @@ -42,7 +42,7 @@ FROM ( FROM ( -- Read From Time Spine 'mf_time_spine' SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + 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 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index 618a05645..834efd8d4 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( , 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/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index 85b20c5d7..6f698ad2f 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: BigQuery -- 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/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 06bdf58c3..467211961 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index de3aa30c2..4a4132f7e 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/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 DATETIME_TRUNC(ds, day) 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/BigQuery/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0.sql index f4b12a8d7..fe3495eb1 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0_optimized.sql index dc9cd5511..a9f0e04cf 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: BigQuery -- 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 ( DATETIME_TRUNC(ds, day) 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/BigQuery/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_filter__plan0.sql index 999f6c319..0e0603623 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( 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/BigQuery/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index c76f36ad9..1f7a1824d 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/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/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index 364344f67..c121e99dd 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: BigQuery --- -- 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 + , DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS ds__week + , DATETIME_TRUNC(time_spine_src_28006.ds, month) AS ds__month + , DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(time_spine_src_28006.ds, year) 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 + , IF(EXTRACT(dayofweek FROM time_spine_src_28006.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28006.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear 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 ( , 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/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index 4bb4638cf..e7f02ec47 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/BigQuery/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 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index cd5b0f741..ff9d01dd9 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index 5990d18b1..c1a13571b 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: Databricks -- 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/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 2309540a0..1bc52f2f4 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index 399086d22..cae1dcf11 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0.sql index 8d1dba903..629960065 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0_optimized.sql index e3aff697e..375262c7f 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Databricks -- 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/Databricks/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_filter__plan0.sql index cf0e7eb66..16a0e0c35 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index dc1e54c55..b1b4d38fa 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/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/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index e7188d22d..51ab633bd 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: Databricks --- -- 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(DAYOFWEEK_ISO 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/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index 3db4958ce..e4cd9eaee 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Databricks/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 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index b0cb402f5..83502418e 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: Postgres --- -- 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/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index e32160833..436df1663 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: Postgres -- 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/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index e793ec07b..60a094b8c 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: Postgres --- -- 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/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index d1a636796..332a1bc9b 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0.sql index bbfe367e4..bfddb4a78 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Postgres --- -- 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/Postgres/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0_optimized.sql index b3aab0ff2..da1a9518f 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Postgres -- 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/Postgres/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_filter__plan0.sql index 9c8e16b6b..a603e2a36 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: Postgres --- -- 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/Postgres/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index 13abbd386..4b272126d 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/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/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index c546f8d7e..61eec3aaa 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: Postgres --- -- 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/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index 91bd1ce2c..68d512f46 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Postgres/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 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index 655a90ba4..99dfa9690 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index d2225e093..6b86be70c 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: Redshift -- 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/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 91361265f..96a312a85 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index 0ac19b1a3..3c9961de4 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0.sql index b9778225f..fe0911868 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0_optimized.sql index 5b0894fa0..51a8c0406 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Redshift -- 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/Redshift/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_filter__plan0.sql index a9c931758..ed5993961 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index 9d727697e..85a1d5d2e 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/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/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index 8c33b63fb..7d0160023 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: Redshift --- -- 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 + , CASE WHEN EXTRACT(dow FROM time_spine_src_28006.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28006.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28006.ds) END 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/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index c9793b14c..849c39099 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Redshift/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 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index ee3f16a50..2c6c6f261 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index 98954f84b..43303bbd7 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: Snowflake -- 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/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 1f0e70a8b..1ba1b0ca9 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index 331e97ac6..987c49122 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0.sql index 2fe7ef70c..e6f31bb81 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0_optimized.sql index 7819cc490..c38495589 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Snowflake -- 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/Snowflake/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_filter__plan0.sql index 88e372e4b..a7f9d92fe 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index 7f6e67f0d..7b6882046 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/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/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index 1f44f6f73..d3c510e16 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: Snowflake --- -- 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(dayofweekiso 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/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index b2a37384b..704c37870 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Snowflake/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 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index 4dd7001fd..152a4d0ba 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,50 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index 98b9811d2..c787cb6c2 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: Trino -- 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/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 5d71cfc2e..ff3dfd9c8 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,53 @@ sql_engine: Trino --- -- 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 timestamp '2020-01-03' AND timestamp '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(DAY_OF_WEEK 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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '2020-01-05' -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day + ) subq_9 + WHERE subq_9.metric_time__day BETWEEN timestamp '2020-01-03' AND timestamp '2020-01-05' +) subq_10 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index ec034f870..ec34f2218 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '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 timestamp '2020-01-03' AND timestamp '2020-01-05' -) subq_17 + subq_19.metric_time__day = subq_15.metric_time__day + WHERE subq_19.metric_time__day BETWEEN timestamp '2020-01-03' AND timestamp '2020-01-05' +) subq_21 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql index 8b2da0017..bea14ccbf 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,41 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql index 31148d821..5a3579c4a 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: Trino -- 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/Trino/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_filter__plan0.sql index baef9e45f..f18adc592 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,41 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index f8f5f9dc0..7f85df947 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/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/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index 636492a10..d9208e2fe 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,49 @@ sql_engine: Trino --- -- 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(DAY_OF_WEEK 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/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index fd38b34a2..fadf7d6cb 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/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