From 778206705f8a693c21333c9fc96e0692e2249a51 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Wed, 11 Dec 2024 11:34:09 -0800 Subject: [PATCH] Include Time Spine Nodes in Dataflow Plan (#1548) Previously, time spine nodes were built on the fly in the dataflow to SQL logic. This came with several limitations, including: - We can't apply where constraints and time constraints using the standard dataflow plan logic. This limitation was the main driver for this PR stack. - We can't track time spines as source nodes. We might want to add these to the dbt DAG at some point. This PR adds logic to build time spine nodes in the dataflow plan, instead. --- .../metricflow_semantics/dag/id_prefix.py | 1 + .../metricflow_semantics/instances.py | 74 ++ .../dataflow/builder/dataflow_plan_builder.py | 137 +- metricflow/dataflow/builder/node_evaluator.py | 6 +- metricflow/dataflow/builder/source_node.py | 28 +- metricflow/dataflow/dataflow_plan_visitor.py | 11 +- metricflow/dataflow/nodes/alias_specs.py | 65 + .../dataflow/nodes/join_to_time_spine.py | 32 +- .../optimizer/predicate_pushdown_optimizer.py | 4 + .../source_scan/cm_branch_combiner.py | 5 + .../source_scan/source_scan_optimizer.py | 5 + metricflow/dataset/sql_dataset.py | 31 +- metricflow/execution/dataflow_to_execution.py | 5 + metricflow/plan_conversion/dataflow_to_sql.py | 161 ++- metricflow/plan_conversion/node_processor.py | 4 +- .../dataflow/builder/test_node_evaluator.py | 8 +- .../source_scan/test_source_scan_optimizer.py | 4 + .../query_output/test_fill_nulls_with_0.py | 62 + .../test_custom_granularity.py | 54 + ...timespine_and_fill_nulls_with_0__plan0.sql | 476 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 66 +- ...timespine_and_fill_nulls_with_0__plan0.sql | 480 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...timespine_and_fill_nulls_with_0__plan0.sql | 480 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...timespine_and_fill_nulls_with_0__plan0.sql | 480 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...timespine_and_fill_nulls_with_0__plan0.sql | 480 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...timespine_and_fill_nulls_with_0__plan0.sql | 480 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...timespine_and_fill_nulls_with_0__plan0.sql | 480 ++++--- ...and_fill_nulls_with_0__plan0_optimized.sql | 68 +- ...timespine_and_fill_nulls_with_0__plan0.xml | 775 +++++++---- ..._metric_with_non_default_grains__plan0.sql | 84 +- ...th_non_default_grains__plan0_optimized.sql | 30 +- ..._metric_with_non_default_grains__plan0.sql | 90 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 90 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 90 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 90 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 90 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_with_non_default_grains__plan0.sql | 90 +- ...th_non_default_grains__plan0_optimized.sql | 36 +- ..._metric_grouped_by_custom_grain__plan0.sql | 50 +- ...ouped_by_custom_grain__plan0_optimized.sql | 24 +- ..._with_custom_granularity_filter__plan0.sql | 392 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 390 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ..._metric_with_custom_granularity__plan0.sql | 72 +- ...th_custom_granularity__plan0_optimized.sql | 16 +- ...nularity_filter_not_in_group_by__plan0.sql | 272 ++-- ...ilter_not_in_group_by__plan0_optimized.sql | 20 +- ..._metric_grouped_by_custom_grain__plan0.sql | 52 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 392 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 390 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ..._metric_with_custom_granularity__plan0.sql | 74 +- ...th_custom_granularity__plan0_optimized.sql | 18 +- ...nularity_filter_not_in_group_by__plan0.sql | 274 ++-- ...ilter_not_in_group_by__plan0_optimized.sql | 20 +- ..._metric_grouped_by_custom_grain__plan0.sql | 52 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 392 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 390 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ..._metric_with_custom_granularity__plan0.sql | 74 +- ...th_custom_granularity__plan0_optimized.sql | 18 +- ...nularity_filter_not_in_group_by__plan0.sql | 274 ++-- ...ilter_not_in_group_by__plan0_optimized.sql | 20 +- ..._metric_grouped_by_custom_grain__plan0.sql | 52 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 392 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 390 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ..._metric_with_custom_granularity__plan0.sql | 74 +- ...th_custom_granularity__plan0_optimized.sql | 18 +- ...nularity_filter_not_in_group_by__plan0.sql | 274 ++-- ...ilter_not_in_group_by__plan0_optimized.sql | 20 +- ..._metric_grouped_by_custom_grain__plan0.sql | 52 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 392 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 390 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ..._metric_with_custom_granularity__plan0.sql | 74 +- ...th_custom_granularity__plan0_optimized.sql | 18 +- ...nularity_filter_not_in_group_by__plan0.sql | 274 ++-- ...ilter_not_in_group_by__plan0_optimized.sql | 20 +- ..._metric_grouped_by_custom_grain__plan0.sql | 52 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 392 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 390 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ..._metric_with_custom_granularity__plan0.sql | 74 +- ...th_custom_granularity__plan0_optimized.sql | 18 +- ...nularity_filter_not_in_group_by__plan0.sql | 274 ++-- ...ilter_not_in_group_by__plan0_optimized.sql | 20 +- ..._metric_grouped_by_custom_grain__plan0.sql | 52 +- ...ouped_by_custom_grain__plan0_optimized.sql | 26 +- ..._with_custom_granularity_filter__plan0.sql | 392 ++++++ ...om_granularity_filter__plan0_optimized.sql | 56 + ...nularity_filter_not_in_group_by__plan0.sql | 390 ++++++ ...ilter_not_in_group_by__plan0_optimized.sql | 56 + ..._metric_with_custom_granularity__plan0.sql | 74 +- ...th_custom_granularity__plan0_optimized.sql | 18 +- ...nularity_filter_not_in_group_by__plan0.sql | 274 ++-- ...ilter_not_in_group_by__plan0_optimized.sql | 20 +- ..._derived_metric_offset_to_grain__dfp_0.xml | 7 +- ...st_derived_metric_offset_window__dfp_0.xml | 7 +- ..._metric_offset_with_granularity__dfp_0.xml | 7 +- ...erived_offset_cumulative_metric__dfp_0.xml | 7 +- ...in_to_time_spine_derived_metric__dfp_0.xml | 17 +- ...join_to_time_spine_with_filters__dfp_0.xml | 13 +- ..._to_time_spine_with_metric_time__dfp_0.xml | 5 + ...erived_metric_with_outer_offset__dfp_0.xml | 12 +- ...ry_have_different_granularities__dfp_0.xml | 7 +- ...ry_have_different_granularities__dfp_0.xml | 9 +- ...set_metric_with_time_constraint__plan0.sql | 266 ++-- ..._with_time_constraint__plan0_optimized.sql | 22 +- ...nth_dimension_and_offset_window__plan0.sql | 66 +- ...ion_and_offset_window__plan0_optimized.sql | 12 +- ...ved_metric_with_offset_to_grain__plan0.sql | 74 +- ..._with_offset_to_grain__plan0_optimized.sql | 20 +- ...offset_to_grain_and_granularity__plan0.sql | 80 +- ...grain_and_granularity__plan0_optimized.sql | 22 +- ...rived_metric_with_offset_window__plan0.sql | 74 +- ...ic_with_offset_window__plan0_optimized.sql | 20 +- ...h_offset_window_and_granularity__plan0.sql | 78 +- ...indow_and_granularity__plan0_optimized.sql | 20 +- ...fset_window_and_offset_to_grain__plan0.sql | 534 ++++---- ...w_and_offset_to_grain__plan0_optimized.sql | 26 +- ...offset_to_grain_and_granularity__plan0.sql | 542 ++++---- ...grain_and_granularity__plan0_optimized.sql | 28 +- ...h_offset_window_and_time_filter__plan0.sql | 272 ++-- ...indow_and_time_filter__plan0_optimized.sql | 24 +- ...erived_offset_cumulative_metric__plan0.sql | 66 +- ...set_cumulative_metric__plan0_optimized.sql | 20 +- ...offset_metric_with_agg_time_dim__plan0.sql | 294 +++-- ...ric_with_agg_time_dim__plan0_optimized.sql | 20 +- ...et_metric_with_one_input_metric__plan0.sql | 66 +- ...with_one_input_metric__plan0_optimized.sql | 12 +- ...d_where_constraint_not_selected__plan0.sql | 142 +- ...nstraint_not_selected__plan0_optimized.sql | 30 +- ...h_offset_multiple_input_metrics__plan0.sql | 280 ++-- ...ultiple_input_metrics__plan0_optimized.sql | 28 +- .../BigQuery/test_nested_offsets__plan0.sql | 118 +- .../test_nested_offsets__plan0_optimized.sql | 24 +- ...ed_offsets_with_time_constraint__plan0.sql | 126 +- ..._with_time_constraint__plan0_optimized.sql | 26 +- ...d_offsets_with_where_constraint__plan0.sql | 124 +- ...with_where_constraint__plan0_optimized.sql | 26 +- ...ry_have_different_granularities__plan0.sql | 270 ++-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 90 +- ...ultiple_granularities__plan0_optimized.sql | 16 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 74 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 20 +- ...ry_have_different_granularities__plan0.sql | 694 +++++----- ...fferent_granularities__plan0_optimized.sql | 26 +- ...w_metric_multiple_granularities__plan0.sql | 338 ++--- ...ultiple_granularities__plan0_optimized.sql | 32 +- ...offset_window_with_agg_time_dim__plan0.sql | 74 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 20 +- ...set_metric_with_time_constraint__plan0.sql | 266 ++-- ..._with_time_constraint__plan0_optimized.sql | 14 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 24 +- ...nth_dimension_and_offset_window__plan0.sql | 70 +- ...ion_and_offset_window__plan0_optimized.sql | 14 +- ...ved_metric_with_offset_to_grain__plan0.sql | 78 +- ..._with_offset_to_grain__plan0_optimized.sql | 24 +- ...offset_to_grain_and_granularity__plan0.sql | 84 +- ...grain_and_granularity__plan0_optimized.sql | 26 +- ...rived_metric_with_offset_window__plan0.sql | 78 +- ...ic_with_offset_window__plan0_optimized.sql | 24 +- ...h_offset_window_and_granularity__plan0.sql | 82 +- ...indow_and_granularity__plan0_optimized.sql | 24 +- ...fset_window_and_offset_to_grain__plan0.sql | 540 ++++---- ...w_and_offset_to_grain__plan0_optimized.sql | 32 +- ...offset_to_grain_and_granularity__plan0.sql | 548 ++++---- ...grain_and_granularity__plan0_optimized.sql | 34 +- ...h_offset_window_and_time_filter__plan0.sql | 276 ++-- ...indow_and_time_filter__plan0_optimized.sql | 26 +- ...erived_offset_cumulative_metric__plan0.sql | 68 +- ...set_cumulative_metric__plan0_optimized.sql | 22 +- ...offset_metric_with_agg_time_dim__plan0.sql | 300 +++-- ...ric_with_agg_time_dim__plan0_optimized.sql | 24 +- ...et_metric_with_one_input_metric__plan0.sql | 68 +- ...with_one_input_metric__plan0_optimized.sql | 14 +- ...d_where_constraint_not_selected__plan0.sql | 146 ++- ...nstraint_not_selected__plan0_optimized.sql | 34 +- ...h_offset_multiple_input_metrics__plan0.sql | 284 ++-- ...ultiple_input_metrics__plan0_optimized.sql | 30 +- .../Databricks/test_nested_offsets__plan0.sql | 120 +- .../test_nested_offsets__plan0_optimized.sql | 26 +- ...ed_offsets_with_time_constraint__plan0.sql | 128 +- ..._with_time_constraint__plan0_optimized.sql | 28 +- ...d_offsets_with_where_constraint__plan0.sql | 126 +- ...with_where_constraint__plan0_optimized.sql | 28 +- ...ry_have_different_granularities__plan0.sql | 272 ++-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 96 +- ...ultiple_granularities__plan0_optimized.sql | 22 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 78 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 24 +- ...ry_have_different_granularities__plan0.sql | 700 +++++----- ...fferent_granularities__plan0_optimized.sql | 28 +- ...w_metric_multiple_granularities__plan0.sql | 356 ++--- ...ultiple_granularities__plan0_optimized.sql | 44 +- ...offset_window_with_agg_time_dim__plan0.sql | 78 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 24 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 16 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 24 +- ...nth_dimension_and_offset_window__plan0.sql | 70 +- ...ion_and_offset_window__plan0_optimized.sql | 14 +- ...ved_metric_with_offset_to_grain__plan0.sql | 78 +- ..._with_offset_to_grain__plan0_optimized.sql | 24 +- ...offset_to_grain_and_granularity__plan0.sql | 84 +- ...grain_and_granularity__plan0_optimized.sql | 26 +- ...rived_metric_with_offset_window__plan0.sql | 78 +- ...ic_with_offset_window__plan0_optimized.sql | 24 +- ...h_offset_window_and_granularity__plan0.sql | 82 +- ...indow_and_granularity__plan0_optimized.sql | 24 +- ...fset_window_and_offset_to_grain__plan0.sql | 540 ++++---- ...w_and_offset_to_grain__plan0_optimized.sql | 32 +- ...offset_to_grain_and_granularity__plan0.sql | 548 ++++---- ...grain_and_granularity__plan0_optimized.sql | 34 +- ...h_offset_window_and_time_filter__plan0.sql | 276 ++-- ...indow_and_time_filter__plan0_optimized.sql | 26 +- ...erived_offset_cumulative_metric__plan0.sql | 68 +- ...set_cumulative_metric__plan0_optimized.sql | 22 +- ...offset_metric_with_agg_time_dim__plan0.sql | 300 +++-- ...ric_with_agg_time_dim__plan0_optimized.sql | 24 +- ...et_metric_with_one_input_metric__plan0.sql | 68 +- ...with_one_input_metric__plan0_optimized.sql | 14 +- ...d_where_constraint_not_selected__plan0.sql | 146 ++- ...nstraint_not_selected__plan0_optimized.sql | 34 +- ...h_offset_multiple_input_metrics__plan0.sql | 284 ++-- ...ultiple_input_metrics__plan0_optimized.sql | 30 +- .../DuckDB/test_nested_offsets__plan0.sql | 120 +- .../test_nested_offsets__plan0_optimized.sql | 26 +- ...ed_offsets_with_time_constraint__plan0.sql | 128 +- ..._with_time_constraint__plan0_optimized.sql | 28 +- ...d_offsets_with_where_constraint__plan0.sql | 126 +- ...with_where_constraint__plan0_optimized.sql | 28 +- ...ry_have_different_granularities__plan0.sql | 272 ++-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 96 +- ...ultiple_granularities__plan0_optimized.sql | 22 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 78 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 24 +- ...ry_have_different_granularities__plan0.sql | 700 +++++----- ...fferent_granularities__plan0_optimized.sql | 28 +- ...w_metric_multiple_granularities__plan0.sql | 356 ++--- ...ultiple_granularities__plan0_optimized.sql | 44 +- ...offset_window_with_agg_time_dim__plan0.sql | 78 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 24 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 16 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 24 +- ...nth_dimension_and_offset_window__plan0.sql | 70 +- ...ion_and_offset_window__plan0_optimized.sql | 14 +- ...ved_metric_with_offset_to_grain__plan0.sql | 78 +- ..._with_offset_to_grain__plan0_optimized.sql | 24 +- ...offset_to_grain_and_granularity__plan0.sql | 84 +- ...grain_and_granularity__plan0_optimized.sql | 26 +- ...rived_metric_with_offset_window__plan0.sql | 78 +- ...ic_with_offset_window__plan0_optimized.sql | 24 +- ...h_offset_window_and_granularity__plan0.sql | 82 +- ...indow_and_granularity__plan0_optimized.sql | 24 +- ...fset_window_and_offset_to_grain__plan0.sql | 540 ++++---- ...w_and_offset_to_grain__plan0_optimized.sql | 32 +- ...offset_to_grain_and_granularity__plan0.sql | 548 ++++---- ...grain_and_granularity__plan0_optimized.sql | 34 +- ...h_offset_window_and_time_filter__plan0.sql | 276 ++-- ...indow_and_time_filter__plan0_optimized.sql | 26 +- ...erived_offset_cumulative_metric__plan0.sql | 68 +- ...set_cumulative_metric__plan0_optimized.sql | 22 +- ...offset_metric_with_agg_time_dim__plan0.sql | 300 +++-- ...ric_with_agg_time_dim__plan0_optimized.sql | 24 +- ...et_metric_with_one_input_metric__plan0.sql | 68 +- ...with_one_input_metric__plan0_optimized.sql | 14 +- ...d_where_constraint_not_selected__plan0.sql | 146 ++- ...nstraint_not_selected__plan0_optimized.sql | 34 +- ...h_offset_multiple_input_metrics__plan0.sql | 284 ++-- ...ultiple_input_metrics__plan0_optimized.sql | 30 +- .../Postgres/test_nested_offsets__plan0.sql | 120 +- .../test_nested_offsets__plan0_optimized.sql | 26 +- ...ed_offsets_with_time_constraint__plan0.sql | 128 +- ..._with_time_constraint__plan0_optimized.sql | 28 +- ...d_offsets_with_where_constraint__plan0.sql | 126 +- ...with_where_constraint__plan0_optimized.sql | 28 +- ...ry_have_different_granularities__plan0.sql | 272 ++-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 96 +- ...ultiple_granularities__plan0_optimized.sql | 22 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 78 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 24 +- ...ry_have_different_granularities__plan0.sql | 700 +++++----- ...fferent_granularities__plan0_optimized.sql | 28 +- ...w_metric_multiple_granularities__plan0.sql | 356 ++--- ...ultiple_granularities__plan0_optimized.sql | 44 +- ...offset_window_with_agg_time_dim__plan0.sql | 78 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 24 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 16 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 24 +- ...nth_dimension_and_offset_window__plan0.sql | 70 +- ...ion_and_offset_window__plan0_optimized.sql | 14 +- ...ved_metric_with_offset_to_grain__plan0.sql | 78 +- ..._with_offset_to_grain__plan0_optimized.sql | 24 +- ...offset_to_grain_and_granularity__plan0.sql | 84 +- ...grain_and_granularity__plan0_optimized.sql | 26 +- ...rived_metric_with_offset_window__plan0.sql | 78 +- ...ic_with_offset_window__plan0_optimized.sql | 24 +- ...h_offset_window_and_granularity__plan0.sql | 82 +- ...indow_and_granularity__plan0_optimized.sql | 24 +- ...fset_window_and_offset_to_grain__plan0.sql | 540 ++++---- ...w_and_offset_to_grain__plan0_optimized.sql | 32 +- ...offset_to_grain_and_granularity__plan0.sql | 548 ++++---- ...grain_and_granularity__plan0_optimized.sql | 34 +- ...h_offset_window_and_time_filter__plan0.sql | 276 ++-- ...indow_and_time_filter__plan0_optimized.sql | 26 +- ...erived_offset_cumulative_metric__plan0.sql | 68 +- ...set_cumulative_metric__plan0_optimized.sql | 22 +- ...offset_metric_with_agg_time_dim__plan0.sql | 300 +++-- ...ric_with_agg_time_dim__plan0_optimized.sql | 24 +- ...et_metric_with_one_input_metric__plan0.sql | 68 +- ...with_one_input_metric__plan0_optimized.sql | 14 +- ...d_where_constraint_not_selected__plan0.sql | 146 ++- ...nstraint_not_selected__plan0_optimized.sql | 34 +- ...h_offset_multiple_input_metrics__plan0.sql | 284 ++-- ...ultiple_input_metrics__plan0_optimized.sql | 30 +- .../Redshift/test_nested_offsets__plan0.sql | 120 +- .../test_nested_offsets__plan0_optimized.sql | 26 +- ...ed_offsets_with_time_constraint__plan0.sql | 128 +- ..._with_time_constraint__plan0_optimized.sql | 28 +- ...d_offsets_with_where_constraint__plan0.sql | 126 +- ...with_where_constraint__plan0_optimized.sql | 28 +- ...ry_have_different_granularities__plan0.sql | 272 ++-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 96 +- ...ultiple_granularities__plan0_optimized.sql | 22 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 78 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 24 +- ...ry_have_different_granularities__plan0.sql | 700 +++++----- ...fferent_granularities__plan0_optimized.sql | 28 +- ...w_metric_multiple_granularities__plan0.sql | 356 ++--- ...ultiple_granularities__plan0_optimized.sql | 44 +- ...offset_window_with_agg_time_dim__plan0.sql | 78 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 24 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 16 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 24 +- ...nth_dimension_and_offset_window__plan0.sql | 70 +- ...ion_and_offset_window__plan0_optimized.sql | 14 +- ...ved_metric_with_offset_to_grain__plan0.sql | 78 +- ..._with_offset_to_grain__plan0_optimized.sql | 24 +- ...offset_to_grain_and_granularity__plan0.sql | 84 +- ...grain_and_granularity__plan0_optimized.sql | 26 +- ...rived_metric_with_offset_window__plan0.sql | 78 +- ...ic_with_offset_window__plan0_optimized.sql | 24 +- ...h_offset_window_and_granularity__plan0.sql | 82 +- ...indow_and_granularity__plan0_optimized.sql | 24 +- ...fset_window_and_offset_to_grain__plan0.sql | 540 ++++---- ...w_and_offset_to_grain__plan0_optimized.sql | 32 +- ...offset_to_grain_and_granularity__plan0.sql | 548 ++++---- ...grain_and_granularity__plan0_optimized.sql | 34 +- ...h_offset_window_and_time_filter__plan0.sql | 276 ++-- ...indow_and_time_filter__plan0_optimized.sql | 26 +- ...erived_offset_cumulative_metric__plan0.sql | 68 +- ...set_cumulative_metric__plan0_optimized.sql | 22 +- ...offset_metric_with_agg_time_dim__plan0.sql | 300 +++-- ...ric_with_agg_time_dim__plan0_optimized.sql | 24 +- ...et_metric_with_one_input_metric__plan0.sql | 68 +- ...with_one_input_metric__plan0_optimized.sql | 14 +- ...d_where_constraint_not_selected__plan0.sql | 146 ++- ...nstraint_not_selected__plan0_optimized.sql | 34 +- ...h_offset_multiple_input_metrics__plan0.sql | 284 ++-- ...ultiple_input_metrics__plan0_optimized.sql | 30 +- .../Snowflake/test_nested_offsets__plan0.sql | 120 +- .../test_nested_offsets__plan0_optimized.sql | 26 +- ...ed_offsets_with_time_constraint__plan0.sql | 128 +- ..._with_time_constraint__plan0_optimized.sql | 28 +- ...d_offsets_with_where_constraint__plan0.sql | 126 +- ...with_where_constraint__plan0_optimized.sql | 28 +- ...ry_have_different_granularities__plan0.sql | 272 ++-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 96 +- ...ultiple_granularities__plan0_optimized.sql | 22 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 78 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 24 +- ...ry_have_different_granularities__plan0.sql | 700 +++++----- ...fferent_granularities__plan0_optimized.sql | 28 +- ...w_metric_multiple_granularities__plan0.sql | 356 ++--- ...ultiple_granularities__plan0_optimized.sql | 44 +- ...offset_window_with_agg_time_dim__plan0.sql | 78 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 24 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 16 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 24 +- ...nth_dimension_and_offset_window__plan0.sql | 70 +- ...ion_and_offset_window__plan0_optimized.sql | 14 +- ...ved_metric_with_offset_to_grain__plan0.sql | 78 +- ..._with_offset_to_grain__plan0_optimized.sql | 24 +- ...offset_to_grain_and_granularity__plan0.sql | 84 +- ...grain_and_granularity__plan0_optimized.sql | 26 +- ...rived_metric_with_offset_window__plan0.sql | 78 +- ...ic_with_offset_window__plan0_optimized.sql | 24 +- ...h_offset_window_and_granularity__plan0.sql | 82 +- ...indow_and_granularity__plan0_optimized.sql | 24 +- ...fset_window_and_offset_to_grain__plan0.sql | 540 ++++---- ...w_and_offset_to_grain__plan0_optimized.sql | 32 +- ...offset_to_grain_and_granularity__plan0.sql | 548 ++++---- ...grain_and_granularity__plan0_optimized.sql | 34 +- ...h_offset_window_and_time_filter__plan0.sql | 276 ++-- ...indow_and_time_filter__plan0_optimized.sql | 26 +- ...erived_offset_cumulative_metric__plan0.sql | 68 +- ...set_cumulative_metric__plan0_optimized.sql | 22 +- ...offset_metric_with_agg_time_dim__plan0.sql | 300 +++-- ...ric_with_agg_time_dim__plan0_optimized.sql | 24 +- ...et_metric_with_one_input_metric__plan0.sql | 68 +- ...with_one_input_metric__plan0_optimized.sql | 14 +- ...d_where_constraint_not_selected__plan0.sql | 146 ++- ...nstraint_not_selected__plan0_optimized.sql | 34 +- ...h_offset_multiple_input_metrics__plan0.sql | 284 ++-- ...ultiple_input_metrics__plan0_optimized.sql | 30 +- .../Trino/test_nested_offsets__plan0.sql | 120 +- .../test_nested_offsets__plan0_optimized.sql | 26 +- ...ed_offsets_with_time_constraint__plan0.sql | 128 +- ..._with_time_constraint__plan0_optimized.sql | 28 +- ...d_offsets_with_where_constraint__plan0.sql | 126 +- ...with_where_constraint__plan0_optimized.sql | 28 +- ...ry_have_different_granularities__plan0.sql | 272 ++-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 96 +- ...ultiple_granularities__plan0_optimized.sql | 22 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 78 +- ...ain_with_agg_time_dim__plan0_optimized.sql | 24 +- ...ry_have_different_granularities__plan0.sql | 700 +++++----- ...fferent_granularities__plan0_optimized.sql | 28 +- ...w_metric_multiple_granularities__plan0.sql | 356 ++--- ...ultiple_granularities__plan0_optimized.sql | 44 +- ...offset_window_with_agg_time_dim__plan0.sql | 78 +- ...dow_with_agg_time_dim__plan0_optimized.sql | 24 +- ...set_metric_with_time_constraint__plan0.sql | 268 ++-- ..._with_time_constraint__plan0_optimized.sql | 16 +- ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++ ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++ ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++ ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++ ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++ ...ustom_granularity_filter__query_output.txt | 6 + ...y_filter_not_in_group_by__query_output.txt | 1005 +++++++++++++++ .../test_cumulative_fill_nulls__plan0.sql | 50 +- ...cumulative_fill_nulls__plan0_optimized.sql | 20 +- ...fill_nulls_for_one_input_metric__plan0.sql | 522 ++++---- ..._for_one_input_metric__plan0_optimized.sql | 32 +- ...ine_with_filter_not_in_group_by__plan0.sql | 70 +- ...ilter_not_in_group_by__plan0_optimized.sql | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 73 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 70 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 70 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 96 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...e_fill_nulls_with_0_metric_time__plan0.sql | 50 +- ...ls_with_0_metric_time__plan0_optimized.sql | 14 +- ..._simple_fill_nulls_with_0_month__plan0.sql | 50 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 18 +- .../test_cumulative_fill_nulls__plan0.sql | 50 +- ...cumulative_fill_nulls__plan0_optimized.sql | 22 +- ...fill_nulls_for_one_input_metric__plan0.sql | 526 ++++---- ..._for_one_input_metric__plan0_optimized.sql | 36 +- ...ine_with_filter_not_in_group_by__plan0.sql | 70 +- ...ilter_not_in_group_by__plan0_optimized.sql | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 73 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 70 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 70 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 96 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...e_fill_nulls_with_0_metric_time__plan0.sql | 50 +- ...ls_with_0_metric_time__plan0_optimized.sql | 14 +- ..._simple_fill_nulls_with_0_month__plan0.sql | 52 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 18 +- .../test_cumulative_fill_nulls__plan0.sql | 50 +- ...cumulative_fill_nulls__plan0_optimized.sql | 22 +- ...fill_nulls_for_one_input_metric__plan0.sql | 526 ++++---- ..._for_one_input_metric__plan0_optimized.sql | 36 +- ...ine_with_filter_not_in_group_by__plan0.sql | 70 +- ...ilter_not_in_group_by__plan0_optimized.sql | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 73 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 70 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 70 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 96 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...e_fill_nulls_with_0_metric_time__plan0.sql | 50 +- ...ls_with_0_metric_time__plan0_optimized.sql | 14 +- ..._simple_fill_nulls_with_0_month__plan0.sql | 52 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 18 +- .../test_cumulative_fill_nulls__plan0.sql | 50 +- ...cumulative_fill_nulls__plan0_optimized.sql | 22 +- ...fill_nulls_for_one_input_metric__plan0.sql | 526 ++++---- ..._for_one_input_metric__plan0_optimized.sql | 36 +- ...ine_with_filter_not_in_group_by__plan0.sql | 70 +- ...ilter_not_in_group_by__plan0_optimized.sql | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 73 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 70 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 70 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 96 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...e_fill_nulls_with_0_metric_time__plan0.sql | 50 +- ...ls_with_0_metric_time__plan0_optimized.sql | 14 +- ..._simple_fill_nulls_with_0_month__plan0.sql | 52 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 18 +- .../test_cumulative_fill_nulls__plan0.sql | 50 +- ...cumulative_fill_nulls__plan0_optimized.sql | 22 +- ...fill_nulls_for_one_input_metric__plan0.sql | 526 ++++---- ..._for_one_input_metric__plan0_optimized.sql | 36 +- ...ine_with_filter_not_in_group_by__plan0.sql | 70 +- ...ilter_not_in_group_by__plan0_optimized.sql | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 73 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 70 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 70 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 96 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...e_fill_nulls_with_0_metric_time__plan0.sql | 50 +- ...ls_with_0_metric_time__plan0_optimized.sql | 14 +- ..._simple_fill_nulls_with_0_month__plan0.sql | 52 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 18 +- .../test_cumulative_fill_nulls__plan0.sql | 50 +- ...cumulative_fill_nulls__plan0_optimized.sql | 22 +- ...fill_nulls_for_one_input_metric__plan0.sql | 526 ++++---- ..._for_one_input_metric__plan0_optimized.sql | 36 +- ...ine_with_filter_not_in_group_by__plan0.sql | 70 +- ...ilter_not_in_group_by__plan0_optimized.sql | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 73 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 70 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 70 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 96 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...e_fill_nulls_with_0_metric_time__plan0.sql | 50 +- ...ls_with_0_metric_time__plan0_optimized.sql | 14 +- ..._simple_fill_nulls_with_0_month__plan0.sql | 52 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 18 +- .../test_cumulative_fill_nulls__plan0.sql | 50 +- ...cumulative_fill_nulls__plan0_optimized.sql | 22 +- ...fill_nulls_for_one_input_metric__plan0.sql | 526 ++++---- ..._for_one_input_metric__plan0_optimized.sql | 36 +- ...ine_with_filter_not_in_group_by__plan0.sql | 70 +- ...ilter_not_in_group_by__plan0_optimized.sql | 24 +- ..._not_in_group_by_using_agg_time__plan0.sql | 73 +- ...oup_by_using_agg_time__plan0_optimized.sql | 24 +- ..._using_agg_time_and_metric_time__plan0.sql | 70 +- ..._time_and_metric_time__plan0_optimized.sql | 24 +- ...th_filter_smaller_than_group_by__plan0.sql | 70 +- ...smaller_than_group_by__plan0_optimized.sql | 24 +- ...join_to_time_spine_with_filters__plan0.sql | 96 +- ...me_spine_with_filters__plan0_optimized.sql | 32 +- ...e_fill_nulls_with_0_metric_time__plan0.sql | 50 +- ...ls_with_0_metric_time__plan0_optimized.sql | 14 +- ..._simple_fill_nulls_with_0_month__plan0.sql | 52 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 18 +- ...st_offset_window_with_date_part__plan0.sql | 78 +- ...window_with_date_part__plan0_optimized.sql | 20 +- ...ides_metric_default_granularity__plan0.sql | 50 +- ...c_default_granularity__plan0_optimized.sql | 12 +- ...daily_join_to_time_spine_metric__plan0.sql | 50 +- ..._to_time_spine_metric__plan0_optimized.sql | 12 +- ...subdaily_offset_to_grain_metric__plan0.sql | 66 +- ...ffset_to_grain_metric__plan0_optimized.sql | 12 +- ...t_subdaily_offset_window_metric__plan0.sql | 66 +- ..._offset_window_metric__plan0_optimized.sql | 12 +- ...ily_time_constraint_with_metric__plan0.sql | 76 +- ...onstraint_with_metric__plan0_optimized.sql | 19 +- ...st_offset_window_with_date_part__plan0.sql | 82 +- ...window_with_date_part__plan0_optimized.sql | 24 +- ...ides_metric_default_granularity__plan0.sql | 50 +- ...c_default_granularity__plan0_optimized.sql | 12 +- ...daily_join_to_time_spine_metric__plan0.sql | 50 +- ..._to_time_spine_metric__plan0_optimized.sql | 12 +- ...subdaily_offset_to_grain_metric__plan0.sql | 68 +- ...ffset_to_grain_metric__plan0_optimized.sql | 14 +- ...t_subdaily_offset_window_metric__plan0.sql | 68 +- ..._offset_window_metric__plan0_optimized.sql | 14 +- ...ily_time_constraint_with_metric__plan0.sql | 76 +- ...onstraint_with_metric__plan0_optimized.sql | 19 +- ...st_offset_window_with_date_part__plan0.sql | 82 +- ...window_with_date_part__plan0_optimized.sql | 24 +- ...ides_metric_default_granularity__plan0.sql | 50 +- ...c_default_granularity__plan0_optimized.sql | 12 +- ...daily_join_to_time_spine_metric__plan0.sql | 50 +- ..._to_time_spine_metric__plan0_optimized.sql | 12 +- ...subdaily_offset_to_grain_metric__plan0.sql | 68 +- ...ffset_to_grain_metric__plan0_optimized.sql | 14 +- ...t_subdaily_offset_window_metric__plan0.sql | 68 +- ..._offset_window_metric__plan0_optimized.sql | 14 +- ...ily_time_constraint_with_metric__plan0.sql | 76 +- ...onstraint_with_metric__plan0_optimized.sql | 19 +- ...st_offset_window_with_date_part__plan0.sql | 82 +- ...window_with_date_part__plan0_optimized.sql | 24 +- ...ides_metric_default_granularity__plan0.sql | 50 +- ...c_default_granularity__plan0_optimized.sql | 12 +- ...daily_join_to_time_spine_metric__plan0.sql | 50 +- ..._to_time_spine_metric__plan0_optimized.sql | 12 +- ...subdaily_offset_to_grain_metric__plan0.sql | 68 +- ...ffset_to_grain_metric__plan0_optimized.sql | 14 +- ...t_subdaily_offset_window_metric__plan0.sql | 68 +- ..._offset_window_metric__plan0_optimized.sql | 14 +- ...ily_time_constraint_with_metric__plan0.sql | 76 +- ...onstraint_with_metric__plan0_optimized.sql | 19 +- ...st_offset_window_with_date_part__plan0.sql | 82 +- ...window_with_date_part__plan0_optimized.sql | 24 +- ...ides_metric_default_granularity__plan0.sql | 50 +- ...c_default_granularity__plan0_optimized.sql | 12 +- ...daily_join_to_time_spine_metric__plan0.sql | 50 +- ..._to_time_spine_metric__plan0_optimized.sql | 12 +- ...subdaily_offset_to_grain_metric__plan0.sql | 68 +- ...ffset_to_grain_metric__plan0_optimized.sql | 14 +- ...t_subdaily_offset_window_metric__plan0.sql | 68 +- ..._offset_window_metric__plan0_optimized.sql | 14 +- ...ily_time_constraint_with_metric__plan0.sql | 76 +- ...onstraint_with_metric__plan0_optimized.sql | 19 +- ...st_offset_window_with_date_part__plan0.sql | 82 +- ...window_with_date_part__plan0_optimized.sql | 24 +- ...ides_metric_default_granularity__plan0.sql | 50 +- ...c_default_granularity__plan0_optimized.sql | 12 +- ...daily_join_to_time_spine_metric__plan0.sql | 50 +- ..._to_time_spine_metric__plan0_optimized.sql | 12 +- ...subdaily_offset_to_grain_metric__plan0.sql | 68 +- ...ffset_to_grain_metric__plan0_optimized.sql | 14 +- ...t_subdaily_offset_window_metric__plan0.sql | 68 +- ..._offset_window_metric__plan0_optimized.sql | 14 +- ...ily_time_constraint_with_metric__plan0.sql | 76 +- ...onstraint_with_metric__plan0_optimized.sql | 19 +- ...st_offset_window_with_date_part__plan0.sql | 82 +- ...window_with_date_part__plan0_optimized.sql | 24 +- ...ides_metric_default_granularity__plan0.sql | 50 +- ...c_default_granularity__plan0_optimized.sql | 12 +- ...daily_join_to_time_spine_metric__plan0.sql | 50 +- ..._to_time_spine_metric__plan0_optimized.sql | 12 +- ...subdaily_offset_to_grain_metric__plan0.sql | 68 +- ...ffset_to_grain_metric__plan0_optimized.sql | 14 +- ...t_subdaily_offset_window_metric__plan0.sql | 68 +- ..._offset_window_metric__plan0_optimized.sql | 14 +- ...ily_time_constraint_with_metric__plan0.sql | 76 +- ...onstraint_with_metric__plan0_optimized.sql | 19 +- ...spine_metric_predicate_pushdown__dfp_0.xml | 26 +- ...pine_metric_predicate_pushdown__dfpo_0.xml | 34 +- ...ost_agg_join_predicate_pushdown__dfp_0.xml | 26 +- ...st_agg_join_predicate_pushdown__dfpo_0.xml | 34 +- ...ffset_metric_predicate_pushdown__dfp_0.xml | 16 +- ...fset_metric_predicate_pushdown__dfpo_0.xml | 24 +- ...spine_metric_predicate_pushdown__plan0.sql | 1132 ++++++++-------- ...ic_predicate_pushdown__plan0_optimized.sql | 66 +- ..._metric_with_query_time_filters__plan0.sql | 632 ++++----- ...th_query_time_filters__plan0_optimized.sql | 38 +- ...ine_pushdown_filter_application__plan0.sql | 60 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ...spine_metric_predicate_pushdown__plan0.sql | 1140 +++++++++-------- ...ic_predicate_pushdown__plan0_optimized.sql | 70 +- ..._metric_with_query_time_filters__plan0.sql | 640 ++++----- ...th_query_time_filters__plan0_optimized.sql | 42 +- ...ine_pushdown_filter_application__plan0.sql | 60 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ...spine_metric_predicate_pushdown__plan0.sql | 1140 +++++++++-------- ...ic_predicate_pushdown__plan0_optimized.sql | 70 +- ..._metric_with_query_time_filters__plan0.sql | 640 ++++----- ...th_query_time_filters__plan0_optimized.sql | 42 +- ...ine_pushdown_filter_application__plan0.sql | 60 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ...spine_metric_predicate_pushdown__plan0.sql | 1140 +++++++++-------- ...ic_predicate_pushdown__plan0_optimized.sql | 70 +- ..._metric_with_query_time_filters__plan0.sql | 640 ++++----- ...th_query_time_filters__plan0_optimized.sql | 42 +- ...ine_pushdown_filter_application__plan0.sql | 60 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ...spine_metric_predicate_pushdown__plan0.sql | 1140 +++++++++-------- ...ic_predicate_pushdown__plan0_optimized.sql | 70 +- ..._metric_with_query_time_filters__plan0.sql | 640 ++++----- ...th_query_time_filters__plan0_optimized.sql | 42 +- ...ine_pushdown_filter_application__plan0.sql | 60 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ...spine_metric_predicate_pushdown__plan0.sql | 1140 +++++++++-------- ...ic_predicate_pushdown__plan0_optimized.sql | 70 +- ..._metric_with_query_time_filters__plan0.sql | 640 ++++----- ...th_query_time_filters__plan0_optimized.sql | 42 +- ...ine_pushdown_filter_application__plan0.sql | 60 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ...spine_metric_predicate_pushdown__plan0.sql | 1140 +++++++++-------- ...ic_predicate_pushdown__plan0_optimized.sql | 70 +- ..._metric_with_query_time_filters__plan0.sql | 640 ++++----- ...th_query_time_filters__plan0_optimized.sql | 42 +- ...ine_pushdown_filter_application__plan0.sql | 60 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ...e_with_input_measure_constraint__plan0.sql | 67 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 76 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../test_simple_join_to_time_spine__plan0.sql | 50 +- ...le_join_to_time_spine__plan0_optimized.sql | 12 +- ..._join_to_time_spine_with_filter__plan0.sql | 50 +- ...ime_spine_with_filter__plan0_optimized.sql | 14 +- ..._time_spine_with_queried_filter__plan0.sql | 60 +- ...e_with_queried_filter__plan0_optimized.sql | 18 +- ...e_with_input_measure_constraint__plan0.sql | 67 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 76 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../test_simple_join_to_time_spine__plan0.sql | 50 +- ...le_join_to_time_spine__plan0_optimized.sql | 12 +- ..._join_to_time_spine_with_filter__plan0.sql | 50 +- ...ime_spine_with_filter__plan0_optimized.sql | 14 +- ..._time_spine_with_queried_filter__plan0.sql | 60 +- ...e_with_queried_filter__plan0_optimized.sql | 18 +- ...e_with_input_measure_constraint__plan0.sql | 67 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 76 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../test_simple_join_to_time_spine__plan0.sql | 50 +- ...le_join_to_time_spine__plan0_optimized.sql | 12 +- ..._join_to_time_spine_with_filter__plan0.sql | 50 +- ...ime_spine_with_filter__plan0_optimized.sql | 14 +- ..._time_spine_with_queried_filter__plan0.sql | 60 +- ...e_with_queried_filter__plan0_optimized.sql | 18 +- ...e_with_input_measure_constraint__plan0.sql | 67 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 76 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../test_simple_join_to_time_spine__plan0.sql | 50 +- ...le_join_to_time_spine__plan0_optimized.sql | 12 +- ..._join_to_time_spine_with_filter__plan0.sql | 50 +- ...ime_spine_with_filter__plan0_optimized.sql | 14 +- ..._time_spine_with_queried_filter__plan0.sql | 60 +- ...e_with_queried_filter__plan0_optimized.sql | 18 +- ...e_with_input_measure_constraint__plan0.sql | 67 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 76 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../test_simple_join_to_time_spine__plan0.sql | 50 +- ...le_join_to_time_spine__plan0_optimized.sql | 12 +- ..._join_to_time_spine_with_filter__plan0.sql | 50 +- ...ime_spine_with_filter__plan0_optimized.sql | 14 +- ..._time_spine_with_queried_filter__plan0.sql | 60 +- ...e_with_queried_filter__plan0_optimized.sql | 18 +- ...e_with_input_measure_constraint__plan0.sql | 67 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 76 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../test_simple_join_to_time_spine__plan0.sql | 50 +- ...le_join_to_time_spine__plan0_optimized.sql | 12 +- ..._join_to_time_spine_with_filter__plan0.sql | 50 +- ...ime_spine_with_filter__plan0_optimized.sql | 14 +- ..._time_spine_with_queried_filter__plan0.sql | 60 +- ...e_with_queried_filter__plan0_optimized.sql | 18 +- ...e_with_input_measure_constraint__plan0.sql | 67 +- ...ut_measure_constraint__plan0_optimized.sql | 20 +- ...ne_with_queried_time_constraint__plan0.sql | 76 +- ...eried_time_constraint__plan0_optimized.sql | 21 +- .../test_simple_join_to_time_spine__plan0.sql | 50 +- ...le_join_to_time_spine__plan0_optimized.sql | 12 +- ..._join_to_time_spine_with_filter__plan0.sql | 50 +- ...ime_spine_with_filter__plan0_optimized.sql | 14 +- ..._time_spine_with_queried_filter__plan0.sql | 60 +- ...e_with_queried_filter__plan0_optimized.sql | 18 +- 804 files changed, 59216 insertions(+), 31423 deletions(-) create mode 100644 metricflow/dataflow/nodes/alias_specs.py 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/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/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/DuckDB/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 create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt diff --git a/metricflow-semantics/metricflow_semantics/dag/id_prefix.py b/metricflow-semantics/metricflow_semantics/dag/id_prefix.py index 2cf673bb22..a9ae0df0ed 100644 --- a/metricflow-semantics/metricflow_semantics/dag/id_prefix.py +++ b/metricflow-semantics/metricflow_semantics/dag/id_prefix.py @@ -55,6 +55,7 @@ class StaticIdPrefix(IdPrefix, Enum, metaclass=EnumMetaClassHelper): DATAFLOW_NODE_ADD_UUID_COLUMN_PREFIX = "auid" DATAFLOW_NODE_JOIN_CONVERSION_EVENTS_PREFIX = "jce" DATAFLOW_NODE_WINDOW_REAGGREGATION_ID_PREFIX = "wr" + DATAFLOW_NODE_ALIAS_SPECS_ID_PREFIX = "as" SQL_EXPR_COLUMN_REFERENCE_ID_PREFIX = "cr" SQL_EXPR_COMPARISON_ID_PREFIX = "cmp" diff --git a/metricflow-semantics/metricflow_semantics/instances.py b/metricflow-semantics/metricflow_semantics/instances.py index bc4e5ae7b1..6cd85fcbd8 100644 --- a/metricflow-semantics/metricflow_semantics/instances.py +++ b/metricflow-semantics/metricflow_semantics/instances.py @@ -58,6 +58,10 @@ def accept(self, visitor: InstanceVisitor[VisitorOutputT]) -> VisitorOutputT: """See Visitable.""" raise NotImplementedError() + def with_new_spec(self, new_spec: SpecT, column_association_resolver: ColumnAssociationResolver) -> MdoInstance: + """Returns a new instance with the spec replaced.""" + raise NotImplementedError() + class LinkableInstance(MdoInstance, Generic[SpecT]): """An MdoInstance whose spec is linkable (i.e., it can have entity links).""" @@ -105,6 +109,17 @@ class MeasureInstance(MdoInstance[MeasureSpec], SemanticModelElementInstance): def accept(self, visitor: InstanceVisitor[VisitorOutputT]) -> VisitorOutputT: # noqa: D102 return visitor.visit_measure_instance(self) + def with_new_spec( + self, new_spec: MeasureSpec, column_association_resolver: ColumnAssociationResolver + ) -> MeasureInstance: + """Returns a new instance with the spec replaced.""" + return MeasureInstance( + associated_columns=(column_association_resolver.resolve_spec(new_spec),), + defined_from=self.defined_from, + spec=new_spec, + aggregation_state=self.aggregation_state, + ) + @dataclass(frozen=True) class DimensionInstance(LinkableInstance[DimensionSpec], SemanticModelElementInstance): # noqa: D101 @@ -125,6 +140,16 @@ def with_entity_prefix( spec=transformed_spec, ) + def with_new_spec( + self, new_spec: DimensionSpec, column_association_resolver: ColumnAssociationResolver + ) -> DimensionInstance: + """Returns a new instance with the spec replaced.""" + return DimensionInstance( + associated_columns=(column_association_resolver.resolve_spec(new_spec),), + defined_from=self.defined_from, + spec=new_spec, + ) + @dataclass(frozen=True) class TimeDimensionInstance(LinkableInstance[TimeDimensionSpec], SemanticModelElementInstance): # noqa: D101 @@ -151,6 +176,16 @@ def with_new_defined_from(self, defined_from: Sequence[SemanticModelElementRefer associated_columns=self.associated_columns, defined_from=tuple(defined_from), spec=self.spec ) + def with_new_spec( + self, new_spec: TimeDimensionSpec, column_association_resolver: ColumnAssociationResolver + ) -> TimeDimensionInstance: + """Returns a new instance with the spec replaced.""" + return TimeDimensionInstance( + associated_columns=(column_association_resolver.resolve_spec(new_spec),), + defined_from=self.defined_from, + spec=new_spec, + ) + @dataclass(frozen=True) class EntityInstance(LinkableInstance[EntitySpec], SemanticModelElementInstance): # noqa: D101 @@ -171,6 +206,16 @@ def with_entity_prefix( spec=transformed_spec, ) + def with_new_spec( + self, new_spec: EntitySpec, column_association_resolver: ColumnAssociationResolver + ) -> EntityInstance: + """Returns a new instance with the spec replaced.""" + return EntityInstance( + associated_columns=(column_association_resolver.resolve_spec(new_spec),), + defined_from=self.defined_from, + spec=new_spec, + ) + @dataclass(frozen=True) class GroupByMetricInstance(LinkableInstance[GroupByMetricSpec], SerializableDataclass): # noqa: D101 @@ -192,6 +237,16 @@ def with_entity_prefix( spec=transformed_spec, ) + def with_new_spec( + self, new_spec: GroupByMetricSpec, column_association_resolver: ColumnAssociationResolver + ) -> GroupByMetricInstance: + """Returns a new instance with the spec replaced.""" + return GroupByMetricInstance( + associated_columns=(column_association_resolver.resolve_spec(new_spec),), + defined_from=self.defined_from, + spec=new_spec, + ) + @dataclass(frozen=True) class MetricInstance(MdoInstance[MetricSpec], SerializableDataclass): # noqa: D101 @@ -202,6 +257,16 @@ class MetricInstance(MdoInstance[MetricSpec], SerializableDataclass): # noqa: D def accept(self, visitor: InstanceVisitor[VisitorOutputT]) -> VisitorOutputT: # noqa: D102 return visitor.visit_metric_instance(self) + def with_new_spec( + self, new_spec: MetricSpec, column_association_resolver: ColumnAssociationResolver + ) -> MetricInstance: + """Returns a new instance with the spec replaced.""" + return MetricInstance( + associated_columns=(column_association_resolver.resolve_spec(new_spec),), + defined_from=self.defined_from, + spec=new_spec, + ) + @dataclass(frozen=True) class MetadataInstance(MdoInstance[MetadataSpec], SerializableDataclass): # noqa: D101 @@ -211,6 +276,15 @@ class MetadataInstance(MdoInstance[MetadataSpec], SerializableDataclass): # noq def accept(self, visitor: InstanceVisitor[VisitorOutputT]) -> VisitorOutputT: # noqa: D102 return visitor.visit_metadata_instance(self) + def with_new_spec( + self, new_spec: MetadataSpec, column_association_resolver: ColumnAssociationResolver + ) -> MetadataInstance: + """Returns a new instance with the spec replaced.""" + return MetadataInstance( + associated_columns=(column_association_resolver.resolve_spec(new_spec),), + spec=new_spec, + ) + # Output type of transform function TransformOutputT = TypeVar("TransformOutputT") diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index 49cd164555..348ba5b4e8 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -1,5 +1,6 @@ from __future__ import annotations +import copy import logging import time from typing import Dict, FrozenSet, List, Optional, Sequence, Set, Tuple, Union @@ -79,6 +80,7 @@ ) from metricflow.dataflow.nodes.add_generated_uuid import AddGeneratedUuidColumnNode from metricflow.dataflow.nodes.aggregate_measures import AggregateMeasuresNode +from metricflow.dataflow.nodes.alias_specs import AliasSpecsNode, SpecToAlias from metricflow.dataflow.nodes.combine_aggregated_outputs import CombineAggregatedOutputsNode from metricflow.dataflow.nodes.compute_metrics import ComputeMetricsNode from metricflow.dataflow.nodes.constrain_time import ConstrainTimeRangeNode @@ -88,8 +90,10 @@ from metricflow.dataflow.nodes.join_to_base import JoinDescription, JoinOnEntitiesNode from metricflow.dataflow.nodes.join_to_custom_granularity import JoinToCustomGranularityNode from metricflow.dataflow.nodes.join_to_time_spine import JoinToTimeSpineNode +from metricflow.dataflow.nodes.metric_time_transform import MetricTimeDimensionTransformNode from metricflow.dataflow.nodes.min_max import MinMaxNode from metricflow.dataflow.nodes.order_by_limit import OrderByLimitNode +from metricflow.dataflow.nodes.read_sql_source import ReadSqlSourceNode from metricflow.dataflow.nodes.semi_additive_join import SemiAdditiveJoinNode from metricflow.dataflow.nodes.where_filter import WhereConstraintNode from metricflow.dataflow.nodes.window_reaggregation_node import WindowReaggregationNode @@ -653,14 +657,19 @@ def _build_derived_metric_output_node( metric_reference=metric_spec.reference, metric_lookup=self._metric_lookup ) if metric_spec.has_time_offset and queried_agg_time_dimension_specs: + # TODO: move this to a helper method + time_spine_node = self._build_time_spine_node(queried_agg_time_dimension_specs) output_node = JoinToTimeSpineNode.create( parent_node=output_node, + time_spine_node=time_spine_node, requested_agg_time_dimension_specs=queried_agg_time_dimension_specs, + join_on_time_dimension_spec=self._sort_by_base_granularity(queried_agg_time_dimension_specs)[0], offset_window=metric_spec.offset_window, offset_to_grain=metric_spec.offset_to_grain, join_type=SqlJoinType.INNER, ) + # TODO: fix bug here where filter specs are being included in when aggregating. if len(metric_spec.filter_spec_set.all_filter_specs) > 0 or predicate_pushdown_state.time_range_constraint: # FilterElementsNode will only be needed if there are where filter specs that were selected in the group by. specs_in_filters = set( @@ -1044,8 +1053,7 @@ def _find_source_node_recipe_non_cached( ) # If metric_time is requested without metrics, choose appropriate time spine node to select those values from. if linkable_specs_to_satisfy.metric_time_specs: - time_spine_source = self._choose_time_spine_source(linkable_specs_to_satisfy.metric_time_specs) - time_spine_node = self._source_node_set.time_spine_nodes[time_spine_source.base_granularity] + time_spine_node = self._choose_time_spine_metric_time_node(linkable_specs_to_satisfy.metric_time_specs) candidate_nodes_for_right_side_of_join += [time_spine_node] candidate_nodes_for_left_side_of_join += [time_spine_node] default_join_type = SqlJoinType.FULL_OUTER @@ -1084,7 +1092,7 @@ def _find_source_node_recipe_non_cached( desired_linkable_specs=linkable_specs_to_satisfy_tuple, nodes=candidate_nodes_for_right_side_of_join, metric_time_dimension_reference=self._metric_time_dimension_reference, - time_spine_nodes=self._source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=self._source_node_set.time_spine_metric_time_nodes_tuple, ) logger.debug( LazyFormat( @@ -1131,7 +1139,7 @@ def _find_source_node_recipe_non_cached( semantic_model_lookup=self._semantic_model_lookup, nodes_available_for_joins=self._sort_by_suitability(candidate_nodes_for_right_side_of_join), node_data_set_resolver=self._node_data_set_resolver, - time_spine_nodes=self._source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=self._source_node_set.time_spine_metric_time_nodes_tuple, ) # Dict from the node that contains the source node to the evaluation results. @@ -1631,15 +1639,22 @@ def _build_aggregated_measure_from_measure_source_node( # If querying an offset metric, join to time spine before aggregation. if before_aggregation_time_spine_join_description and base_queried_agg_time_dimension_specs: + # TODO: move all of this to a helper function assert before_aggregation_time_spine_join_description.join_type is SqlJoinType.INNER, ( f"Expected {SqlJoinType.INNER} for joining to time spine before aggregation. Remove this if there's a " f"new use case." ) - # This also uses the original time range constraint due to the application of the time window intervals - # in join rendering + + join_on_time_dimension_spec = self._determine_time_spine_join_spec( + measure_properties=measure_properties, required_time_spine_specs=base_queried_agg_time_dimension_specs + ) + required_time_spine_specs = (join_on_time_dimension_spec,) + base_queried_agg_time_dimension_specs + time_spine_node = self._build_time_spine_node(required_time_spine_specs) unaggregated_measure_node = JoinToTimeSpineNode.create( parent_node=unaggregated_measure_node, + time_spine_node=time_spine_node, requested_agg_time_dimension_specs=base_queried_agg_time_dimension_specs, + join_on_time_dimension_spec=join_on_time_dimension_spec, offset_window=before_aggregation_time_spine_join_description.offset_window, offset_to_grain=before_aggregation_time_spine_join_description.offset_to_grain, join_type=before_aggregation_time_spine_join_description.join_type, @@ -1682,10 +1697,13 @@ def _build_aggregated_measure_from_measure_source_node( measure_reference=measure_spec.reference, semantic_model_lookup=self._semantic_model_lookup ) if after_aggregation_time_spine_join_description and queried_agg_time_dimension_specs: + # TODO: move all of this to a helper function assert after_aggregation_time_spine_join_description.join_type is SqlJoinType.LEFT_OUTER, ( f"Expected {SqlJoinType.LEFT_OUTER} for joining to time spine after aggregation. Remove this if " f"there's a new use case." ) + time_spine_required_specs = copy.deepcopy(queried_agg_time_dimension_specs) + # Find filters that contain only metric_time or agg_time_dimension. They will be applied to the time spine table. agg_time_only_filters: List[WhereFilterSpec] = [] non_agg_time_filters: List[WhereFilterSpec] = [] @@ -1695,24 +1713,23 @@ def _build_aggregated_measure_from_measure_source_node( ) if set(included_agg_time_specs) == set(filter_spec.linkable_spec_set.as_tuple): agg_time_only_filters.append(filter_spec) - if filter_spec.linkable_spec_set.time_dimension_specs_with_custom_grain: - raise ValueError( - "Using custom granularity in filters for `join_to_timespine` metrics is not yet fully supported. " - "This feature is coming soon!" - ) + for agg_time_spec in included_agg_time_specs: + if agg_time_spec not in time_spine_required_specs: + time_spine_required_specs.append(agg_time_spec) else: non_agg_time_filters.append(filter_spec) - # TODO: split this node into TimeSpineSourceNode and JoinToTimeSpineNode - then can use standard nodes here - # like JoinToCustomGranularityNode, WhereConstraintNode, etc. + time_spine_node = self._build_time_spine_node( + queried_time_spine_specs=queried_agg_time_dimension_specs, + time_range_constraint=predicate_pushdown_state.time_range_constraint, + where_filter_specs=agg_time_only_filters, + ) output_node: DataflowPlanNode = JoinToTimeSpineNode.create( parent_node=aggregate_measures_node, + time_spine_node=time_spine_node, requested_agg_time_dimension_specs=queried_agg_time_dimension_specs, + join_on_time_dimension_spec=self._sort_by_base_granularity(queried_agg_time_dimension_specs)[0], join_type=after_aggregation_time_spine_join_description.join_type, - time_range_constraint=predicate_pushdown_state.time_range_constraint, - offset_window=after_aggregation_time_spine_join_description.offset_window, - offset_to_grain=after_aggregation_time_spine_join_description.offset_to_grain, - time_spine_filters=agg_time_only_filters, ) # Since new rows might have been added due to time spine join, re-apply constraints here. Only re-apply filters @@ -1828,3 +1845,89 @@ def _choose_time_spine_source(self, required_time_spine_specs: Sequence[TimeDime required_time_spine_specs=required_time_spine_specs, time_spine_sources=self._source_node_builder.time_spine_sources, ) + + def _choose_time_spine_metric_time_node( + self, required_time_spine_specs: Sequence[TimeDimensionSpec] + ) -> MetricTimeDimensionTransformNode: + """Return the MetricTimeDimensionTransform time spine node needed to satisfy the specs.""" + time_spine_source = self._choose_time_spine_source(required_time_spine_specs) + return self._source_node_set.time_spine_metric_time_nodes[time_spine_source.base_granularity] + + def _choose_time_spine_read_node(self, time_spine_source: TimeSpineSource) -> ReadSqlSourceNode: + """Return the MetricTimeDimensionTransform time spine node needed to satisfy the specs.""" + return self._source_node_set.time_spine_read_nodes[time_spine_source.base_granularity] + + def _build_time_spine_node( + self, + queried_time_spine_specs: Sequence[TimeDimensionSpec], + where_filter_specs: Sequence[WhereFilterSpec] = (), + time_range_constraint: Optional[TimeRangeConstraint] = None, + ) -> DataflowPlanNode: + """Return the time spine node needed to satisfy the specs.""" + required_time_spine_spec_set = self.__get_required_linkable_specs( + queried_linkable_specs=LinkableSpecSet(time_dimension_specs=tuple(queried_time_spine_specs)), + filter_specs=where_filter_specs, + ) + required_time_spine_specs = required_time_spine_spec_set.time_dimension_specs + + # TODO: support multiple time spines here. Build node on the one with the smallest base grain. + # Then, pass custom_granularity_specs into _build_pre_aggregation_plan if they aren't satisfied by smallest time spine. + time_spine_source = self._choose_time_spine_source(required_time_spine_specs) + read_node = self._choose_time_spine_read_node(time_spine_source) + time_spine_data_set = self._node_data_set_resolver.get_output_data_set(read_node) + + # Change the column aliases to match the specs that were requested in the query. + time_spine_node = AliasSpecsNode.create( + parent_node=read_node, + change_specs=tuple( + SpecToAlias( + input_spec=time_spine_data_set.instance_from_time_dimension_grain_and_date_part(required_spec).spec, + output_spec=required_spec, + ) + for required_spec in required_time_spine_specs + ), + ) + + # If the base grain of the time spine isn't selected, it will have duplicate rows that need deduping. + should_dedupe = ExpandedTimeGranularity.from_time_granularity(time_spine_source.base_granularity) not in { + spec.time_granularity for spec in queried_time_spine_specs + } + + return self._build_pre_aggregation_plan( + source_node=time_spine_node, + filter_to_specs=InstanceSpecSet(time_dimension_specs=tuple(queried_time_spine_specs)), + time_range_constraint=time_range_constraint, + where_filter_specs=where_filter_specs, + distinct=should_dedupe, + ) + + def _sort_by_base_granularity(self, time_dimension_specs: Sequence[TimeDimensionSpec]) -> List[TimeDimensionSpec]: + """Sort the time dimensions by their base granularity. + + Specs with date part will come after specs without it. Standard grains will come before custom. + """ + return sorted( + time_dimension_specs, + key=lambda spec: ( + spec.date_part is not None, + spec.time_granularity.is_custom_granularity, + spec.time_granularity.base_granularity.to_int(), + ), + ) + + def _determine_time_spine_join_spec( + self, measure_properties: MeasureSpecProperties, required_time_spine_specs: Tuple[TimeDimensionSpec, ...] + ) -> TimeDimensionSpec: + """Determine the spec to join on for a time spine join. + + Defaults to metric_time if it is included in the request, else the agg_time_dimension. + Will use the smallest available grain for the meeasure. + """ + join_spec_grain = ExpandedTimeGranularity.from_time_granularity(measure_properties.agg_time_dimension_grain) + join_on_time_dimension_spec = DataSet.metric_time_dimension_spec(time_granularity=join_spec_grain) + if not LinkableSpecSet(time_dimension_specs=required_time_spine_specs).contains_metric_time: + sample_agg_time_dimension_spec = required_time_spine_specs[0] + join_on_time_dimension_spec = sample_agg_time_dimension_spec.with_grain_and_date_part( + time_granularity=join_spec_grain, date_part=None + ) + return join_on_time_dimension_spec diff --git a/metricflow/dataflow/builder/node_evaluator.py b/metricflow/dataflow/builder/node_evaluator.py index fbc11da094..fb62adc915 100644 --- a/metricflow/dataflow/builder/node_evaluator.py +++ b/metricflow/dataflow/builder/node_evaluator.py @@ -169,7 +169,7 @@ def __init__( semantic_model_lookup: SemanticModelLookup, nodes_available_for_joins: Sequence[DataflowPlanNode], node_data_set_resolver: DataflowPlanNodeOutputDataSetResolver, - time_spine_nodes: Sequence[MetricTimeDimensionTransformNode], + time_spine_metric_time_nodes: Sequence[MetricTimeDimensionTransformNode], ) -> None: """Initializer. @@ -186,7 +186,7 @@ def __init__( self._node_data_set_resolver = node_data_set_resolver self._partition_resolver = PartitionJoinResolver(self._semantic_model_lookup) self._join_evaluator = SemanticModelJoinEvaluator(self._semantic_model_lookup) - self._time_spine_nodes = time_spine_nodes + self._time_spine_metric_time_nodes = time_spine_metric_time_nodes def _find_joinable_candidate_nodes_that_can_satisfy_linkable_specs( self, @@ -205,7 +205,7 @@ def _find_joinable_candidate_nodes_that_can_satisfy_linkable_specs( linkable_specs_in_right_node = data_set_in_right_node.instance_set.spec_set.linkable_specs # If right node is time spine source node, use cross join. - if right_node in self._time_spine_nodes: + if right_node in self._time_spine_metric_time_nodes: satisfiable_metric_time_specs = [ spec for spec in linkable_specs_in_right_node if spec in needed_linkable_specs ] diff --git a/metricflow/dataflow/builder/source_node.py b/metricflow/dataflow/builder/source_node.py index 575668eabb..1e84980179 100644 --- a/metricflow/dataflow/builder/source_node.py +++ b/metricflow/dataflow/builder/source_node.py @@ -36,20 +36,23 @@ class SourceNodeSet: # Semantic models are 1:1 mapped to a ReadSqlSourceNode. source_nodes_for_group_by_item_queries: Tuple[DataflowPlanNode, ...] - # Provides the time spines. - time_spine_nodes: Mapping[TimeGranularity, MetricTimeDimensionTransformNode] + # Provides time spines that can be used to satisfy time spine joins. + time_spine_read_nodes: Mapping[TimeGranularity, ReadSqlSourceNode] + + # Provides time spines that can be used to satisfy metric_time without metrics. + time_spine_metric_time_nodes: Mapping[TimeGranularity, MetricTimeDimensionTransformNode] @property def all_nodes(self) -> Sequence[DataflowPlanNode]: # noqa: D102 return ( self.source_nodes_for_metric_queries + self.source_nodes_for_group_by_item_queries - + self.time_spine_nodes_tuple + + self.time_spine_metric_time_nodes_tuple ) @property - def time_spine_nodes_tuple(self) -> Tuple[MetricTimeDimensionTransformNode, ...]: # noqa: D102 - return tuple(self.time_spine_nodes.values()) + def time_spine_metric_time_nodes_tuple(self) -> Tuple[MetricTimeDimensionTransformNode, ...]: # noqa: D102 + return tuple(self.time_spine_metric_time_nodes.values()) class SourceNodeBuilder: @@ -65,11 +68,15 @@ def __init__( # noqa: D107 self.time_spine_sources = TimeSpineSource.build_standard_time_spine_sources( semantic_manifest_lookup.semantic_manifest ) - self._time_spine_source_nodes = {} - for granularity, time_spine_source in self.time_spine_sources.items(): + + self._time_spine_read_nodes = {} + self._time_spine_metric_time_nodes = {} + for base_granularity, time_spine_source in self.time_spine_sources.items(): data_set = data_set_converter.build_time_spine_source_data_set(time_spine_source) - self._time_spine_source_nodes[granularity] = MetricTimeDimensionTransformNode.create( - parent_node=ReadSqlSourceNode.create(data_set), + read_node = ReadSqlSourceNode.create(data_set) + self._time_spine_read_nodes[base_granularity] = read_node + self._time_spine_metric_time_nodes[base_granularity] = MetricTimeDimensionTransformNode.create( + parent_node=read_node, aggregation_time_dimension_reference=TimeDimensionReference(time_spine_source.base_column), ) @@ -103,7 +110,8 @@ def create_from_data_sets(self, data_sets: Sequence[SemanticModelDataSet]) -> So source_nodes_for_metric_queries.append(metric_time_transform_node) return SourceNodeSet( - time_spine_nodes=self._time_spine_source_nodes, + time_spine_metric_time_nodes=self._time_spine_metric_time_nodes, + time_spine_read_nodes=self._time_spine_read_nodes, source_nodes_for_group_by_item_queries=tuple(group_by_item_source_nodes), source_nodes_for_metric_queries=tuple(source_nodes_for_metric_queries), ) diff --git a/metricflow/dataflow/dataflow_plan_visitor.py b/metricflow/dataflow/dataflow_plan_visitor.py index 4c6ad85620..412170a53f 100644 --- a/metricflow/dataflow/dataflow_plan_visitor.py +++ b/metricflow/dataflow/dataflow_plan_visitor.py @@ -11,6 +11,7 @@ from metricflow.dataflow.dataflow_plan import DataflowPlanNode from metricflow.dataflow.nodes.add_generated_uuid import AddGeneratedUuidColumnNode from metricflow.dataflow.nodes.aggregate_measures import AggregateMeasuresNode + from metricflow.dataflow.nodes.alias_specs import AliasSpecsNode from metricflow.dataflow.nodes.combine_aggregated_outputs import CombineAggregatedOutputsNode from metricflow.dataflow.nodes.compute_metrics import ComputeMetricsNode from metricflow.dataflow.nodes.constrain_time import ConstrainTimeRangeNode @@ -121,6 +122,10 @@ def visit_join_conversion_events_node(self, node: JoinConversionEventsNode) -> V def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNode) -> VisitorOutputT: # noqa: D102 raise NotImplementedError + @abstractmethod + def visit_alias_specs_node(self, node: AliasSpecsNode) -> VisitorOutputT: # noqa: D102 + raise NotImplementedError + class DataflowPlanNodeVisitorWithDefaultHandler(DataflowPlanNodeVisitor[VisitorOutputT], Generic[VisitorOutputT]): """Similar to `DataflowPlanNodeVisitor`, but with an abstract default handler that gets called for each node. @@ -191,7 +196,7 @@ def visit_semi_additive_join_node(self, node: SemiAdditiveJoinNode) -> VisitorOu @override def visit_metric_time_dimension_transform_node( # noqa: D102 self, node: MetricTimeDimensionTransformNode - ) -> VisitorOutputT: # noqa: D102 + ) -> VisitorOutputT: return self._default_handler(node) @override @@ -213,3 +218,7 @@ def visit_join_conversion_events_node(self, node: JoinConversionEventsNode) -> V @override def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNode) -> VisitorOutputT: # noqa: D102 return self._default_handler(node) + + @override + def visit_alias_specs_node(self, node: AliasSpecsNode) -> VisitorOutputT: # noqa: D102 + return self._default_handler(node) diff --git a/metricflow/dataflow/nodes/alias_specs.py b/metricflow/dataflow/nodes/alias_specs.py new file mode 100644 index 0000000000..33e5467ef8 --- /dev/null +++ b/metricflow/dataflow/nodes/alias_specs.py @@ -0,0 +1,65 @@ +from __future__ import annotations + +from abc import ABC +from dataclasses import dataclass +from typing import Sequence, Tuple + +from metricflow_semantics.dag.id_prefix import IdPrefix, StaticIdPrefix +from metricflow_semantics.dag.mf_dag import DisplayedProperty +from metricflow_semantics.specs.instance_spec import InstanceSpec +from metricflow_semantics.visitor import VisitorOutputT + +from metricflow.dataflow.dataflow_plan import DataflowPlanNode +from metricflow.dataflow.dataflow_plan_visitor import DataflowPlanNodeVisitor + + +@dataclass +class SpecToAlias: + """A mapping of an input spec that should be aliased to match an output spec.""" + + input_spec: InstanceSpec + output_spec: InstanceSpec + + +@dataclass(frozen=True, eq=False) +class AliasSpecsNode(DataflowPlanNode, ABC): + """Change the columns matching the key specs to match the value specs.""" + + change_specs: Tuple[SpecToAlias, ...] + + def __post_init__(self) -> None: # noqa: D105 + super().__post_init__() + assert len(self.change_specs) > 0, "Must have at least one value in change_specs for AliasSpecsNode." + + @staticmethod + def create(parent_node: DataflowPlanNode, change_specs: Tuple[SpecToAlias, ...]) -> AliasSpecsNode: # noqa: D102 + return AliasSpecsNode(parent_nodes=(parent_node,), change_specs=change_specs) + + @classmethod + def id_prefix(cls) -> IdPrefix: # noqa: D102 + return StaticIdPrefix.DATAFLOW_NODE_ALIAS_SPECS_ID_PREFIX + + def accept(self, visitor: DataflowPlanNodeVisitor[VisitorOutputT]) -> VisitorOutputT: # noqa: D102 + return visitor.visit_alias_specs_node(self) + + @property + def description(self) -> str: # noqa: D102 + return """Change Column Aliases""" + + @property + def displayed_properties(self) -> Sequence[DisplayedProperty]: # noqa: D102 + return tuple(super().displayed_properties) + (DisplayedProperty("change_specs", self.change_specs),) + + @property + def parent_node(self) -> DataflowPlanNode: # noqa: D102 + return self.parent_nodes[0] + + def functionally_identical(self, other_node: DataflowPlanNode) -> bool: # noqa: D102 + return isinstance(other_node, self.__class__) and other_node.change_specs == self.change_specs + + def with_new_parents(self, new_parent_nodes: Sequence[DataflowPlanNode]) -> AliasSpecsNode: # noqa: D102 + assert len(new_parent_nodes) == 1, "AliasSpecsNode accepts exactly one parent node." + return AliasSpecsNode.create( + parent_node=new_parent_nodes[0], + change_specs=self.change_specs, + ) diff --git a/metricflow/dataflow/nodes/join_to_time_spine.py b/metricflow/dataflow/nodes/join_to_time_spine.py index fd86503813..b33a3ff6d1 100644 --- a/metricflow/dataflow/nodes/join_to_time_spine.py +++ b/metricflow/dataflow/nodes/join_to_time_spine.py @@ -8,9 +8,7 @@ from dbt_semantic_interfaces.type_enums import TimeGranularity from metricflow_semantics.dag.id_prefix import IdPrefix, StaticIdPrefix from metricflow_semantics.dag.mf_dag import DisplayedProperty -from metricflow_semantics.filters.time_constraint import TimeRangeConstraint from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec -from metricflow_semantics.specs.where_filter.where_filter_spec import WhereFilterSpec from metricflow_semantics.sql.sql_join_type import SqlJoinType from metricflow_semantics.visitor import VisitorOutputT @@ -25,17 +23,17 @@ class JoinToTimeSpineNode(DataflowPlanNode, ABC): Attributes: requested_agg_time_dimension_specs: Time dimensions requested in the query. join_type: Join type to use when joining to time spine. - time_range_constraint: Time range to constrain the time spine to. + join_on_time_dimension_spec: The time dimension to use in the join ON condition. offset_window: Time window to offset the parent dataset by when joining to time spine. offset_to_grain: Granularity period to offset the parent dataset to when joining to time spine. """ + time_spine_node: DataflowPlanNode requested_agg_time_dimension_specs: Sequence[TimeDimensionSpec] + join_on_time_dimension_spec: TimeDimensionSpec join_type: SqlJoinType - time_range_constraint: Optional[TimeRangeConstraint] offset_window: Optional[MetricTimeWindow] offset_to_grain: Optional[TimeGranularity] - time_spine_filters: Optional[Sequence[WhereFilterSpec]] = None def __post_init__(self) -> None: # noqa: D105 super().__post_init__() @@ -51,21 +49,21 @@ def __post_init__(self) -> None: # noqa: D105 @staticmethod def create( # noqa: D102 parent_node: DataflowPlanNode, + time_spine_node: DataflowPlanNode, requested_agg_time_dimension_specs: Sequence[TimeDimensionSpec], + join_on_time_dimension_spec: TimeDimensionSpec, join_type: SqlJoinType, - time_range_constraint: Optional[TimeRangeConstraint] = None, offset_window: Optional[MetricTimeWindow] = None, offset_to_grain: Optional[TimeGranularity] = None, - time_spine_filters: Optional[Sequence[WhereFilterSpec]] = None, ) -> JoinToTimeSpineNode: return JoinToTimeSpineNode( parent_nodes=(parent_node,), + time_spine_node=time_spine_node, requested_agg_time_dimension_specs=tuple(requested_agg_time_dimension_specs), + join_on_time_dimension_spec=join_on_time_dimension_spec, join_type=join_type, - time_range_constraint=time_range_constraint, offset_window=offset_window, offset_to_grain=offset_to_grain, - time_spine_filters=time_spine_filters, ) @classmethod @@ -83,20 +81,13 @@ def description(self) -> str: # noqa: D102 def displayed_properties(self) -> Sequence[DisplayedProperty]: # noqa: D102 props = tuple(super().displayed_properties) + ( DisplayedProperty("requested_agg_time_dimension_specs", self.requested_agg_time_dimension_specs), + DisplayedProperty("join_on_time_dimension_spec", self.join_on_time_dimension_spec), DisplayedProperty("join_type", self.join_type), ) if self.offset_window: props += (DisplayedProperty("offset_window", self.offset_window),) if self.offset_to_grain: props += (DisplayedProperty("offset_to_grain", self.offset_to_grain),) - if self.time_range_constraint: - props += (DisplayedProperty("time_range_constraint", self.time_range_constraint),) - if self.time_spine_filters: - props += ( - DisplayedProperty( - "time_spine_filters", [time_spine_filter.where_sql for time_spine_filter in self.time_spine_filters] - ), - ) return props @property @@ -106,22 +97,21 @@ def parent_node(self) -> DataflowPlanNode: # noqa: D102 def functionally_identical(self, other_node: DataflowPlanNode) -> bool: # noqa: D102 return ( isinstance(other_node, self.__class__) - and other_node.time_range_constraint == self.time_range_constraint and other_node.offset_window == self.offset_window and other_node.offset_to_grain == self.offset_to_grain and other_node.requested_agg_time_dimension_specs == self.requested_agg_time_dimension_specs + and other_node.join_on_time_dimension_spec == self.join_on_time_dimension_spec and other_node.join_type == self.join_type - and other_node.time_spine_filters == self.time_spine_filters ) def with_new_parents(self, new_parent_nodes: Sequence[DataflowPlanNode]) -> JoinToTimeSpineNode: # noqa: D102 assert len(new_parent_nodes) == 1 return JoinToTimeSpineNode.create( parent_node=new_parent_nodes[0], + time_spine_node=self.time_spine_node, requested_agg_time_dimension_specs=self.requested_agg_time_dimension_specs, - time_range_constraint=self.time_range_constraint, offset_window=self.offset_window, offset_to_grain=self.offset_to_grain, join_type=self.join_type, - time_spine_filters=self.time_spine_filters, + join_on_time_dimension_spec=self.join_on_time_dimension_spec, ) diff --git a/metricflow/dataflow/optimizer/predicate_pushdown_optimizer.py b/metricflow/dataflow/optimizer/predicate_pushdown_optimizer.py index ba9e6d7661..223964af40 100644 --- a/metricflow/dataflow/optimizer/predicate_pushdown_optimizer.py +++ b/metricflow/dataflow/optimizer/predicate_pushdown_optimizer.py @@ -19,6 +19,7 @@ from metricflow.dataflow.dataflow_plan_visitor import DataflowPlanNodeVisitor from metricflow.dataflow.nodes.add_generated_uuid import AddGeneratedUuidColumnNode from metricflow.dataflow.nodes.aggregate_measures import AggregateMeasuresNode +from metricflow.dataflow.nodes.alias_specs import AliasSpecsNode from metricflow.dataflow.nodes.combine_aggregated_outputs import CombineAggregatedOutputsNode from metricflow.dataflow.nodes.compute_metrics import ComputeMetricsNode from metricflow.dataflow.nodes.constrain_time import ConstrainTimeRangeNode @@ -468,6 +469,9 @@ def visit_join_to_custom_granularity_node( # noqa: D102 ) -> OptimizeBranchResult: raise NotImplementedError + def visit_alias_specs_node(self, node: AliasSpecsNode) -> OptimizeBranchResult: # noqa: D102 + raise NotImplementedError + def visit_join_on_entities_node(self, node: JoinOnEntitiesNode) -> OptimizeBranchResult: """Handles pushdown state propagation for the standard join node type. diff --git a/metricflow/dataflow/optimizer/source_scan/cm_branch_combiner.py b/metricflow/dataflow/optimizer/source_scan/cm_branch_combiner.py index cad82f2155..233629e7a6 100644 --- a/metricflow/dataflow/optimizer/source_scan/cm_branch_combiner.py +++ b/metricflow/dataflow/optimizer/source_scan/cm_branch_combiner.py @@ -13,6 +13,7 @@ from metricflow.dataflow.dataflow_plan_visitor import DataflowPlanNodeVisitor from metricflow.dataflow.nodes.add_generated_uuid import AddGeneratedUuidColumnNode from metricflow.dataflow.nodes.aggregate_measures import AggregateMeasuresNode +from metricflow.dataflow.nodes.alias_specs import AliasSpecsNode from metricflow.dataflow.nodes.combine_aggregated_outputs import CombineAggregatedOutputsNode from metricflow.dataflow.nodes.compute_metrics import ComputeMetricsNode from metricflow.dataflow.nodes.constrain_time import ConstrainTimeRangeNode @@ -467,3 +468,7 @@ def visit_join_to_custom_granularity_node( # noqa: D102 def visit_min_max_node(self, node: MinMaxNode) -> ComputeMetricsBranchCombinerResult: # noqa: D102 self._log_visit_node_type(node) return self._default_handler(node) + + def visit_alias_specs_node(self, node: AliasSpecsNode) -> ComputeMetricsBranchCombinerResult: # noqa: D102 + self._log_visit_node_type(node) + return self._default_handler(node) diff --git a/metricflow/dataflow/optimizer/source_scan/source_scan_optimizer.py b/metricflow/dataflow/optimizer/source_scan/source_scan_optimizer.py index 31a31c9ce0..c84035335e 100644 --- a/metricflow/dataflow/optimizer/source_scan/source_scan_optimizer.py +++ b/metricflow/dataflow/optimizer/source_scan/source_scan_optimizer.py @@ -15,6 +15,7 @@ from metricflow.dataflow.dataflow_plan_visitor import DataflowPlanNodeVisitor from metricflow.dataflow.nodes.add_generated_uuid import AddGeneratedUuidColumnNode from metricflow.dataflow.nodes.aggregate_measures import AggregateMeasuresNode +from metricflow.dataflow.nodes.alias_specs import AliasSpecsNode from metricflow.dataflow.nodes.combine_aggregated_outputs import CombineAggregatedOutputsNode from metricflow.dataflow.nodes.compute_metrics import ComputeMetricsNode from metricflow.dataflow.nodes.constrain_time import ConstrainTimeRangeNode @@ -351,3 +352,7 @@ def visit_join_to_custom_granularity_node( # noqa: D102 def visit_min_max_node(self, node: MinMaxNode) -> OptimizeBranchResult: # noqa: D102 self._log_visit_node_type(node) return self._default_base_output_handler(node) + + def visit_alias_specs_node(self, node: AliasSpecsNode) -> OptimizeBranchResult: # noqa: D102 + self._log_visit_node_type(node) + return self._default_base_output_handler(node) diff --git a/metricflow/dataset/sql_dataset.py b/metricflow/dataset/sql_dataset.py index 4bb530e71d..afa5593879 100644 --- a/metricflow/dataset/sql_dataset.py +++ b/metricflow/dataset/sql_dataset.py @@ -5,11 +5,12 @@ from dbt_semantic_interfaces.references import SemanticModelReference from metricflow_semantics.assert_one_arg import assert_exactly_one_arg_set -from metricflow_semantics.instances import EntityInstance, InstanceSet, TimeDimensionInstance +from metricflow_semantics.instances import EntityInstance, InstanceSet, MdoInstance, TimeDimensionInstance from metricflow_semantics.mf_logging.lazy_formattable import LazyFormat from metricflow_semantics.specs.column_assoc import ColumnAssociation from metricflow_semantics.specs.dimension_spec import DimensionSpec from metricflow_semantics.specs.entity_spec import EntitySpec +from metricflow_semantics.specs.instance_spec import InstanceSpec from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec from typing_extensions import override @@ -144,7 +145,7 @@ def instances_for_time_dimensions( return instances_to_return def instance_for_time_dimension(self, time_dimension_spec: TimeDimensionSpec) -> TimeDimensionInstance: - """Given the name of the time dimension, return the instance associated with it in the data set.""" + """Given a time dimension spec, return the instance associated with it in the data set.""" instances = self.instances_for_time_dimensions((time_dimension_spec,)) if not len(instances) == 1: raise RuntimeError( @@ -153,6 +154,32 @@ def instance_for_time_dimension(self, time_dimension_spec: TimeDimensionSpec) -> ) return instances[0] + def instance_for_spec(self, spec: InstanceSpec) -> MdoInstance: + """Given a spec, return the instance associated with it in the data set.""" + instances = self.instance_set.as_tuple + for instance in instances: + if instance.spec == spec: + return instance + raise RuntimeError( + str(LazyFormat("Did not find instance matching spec in dataset.", spec=spec, instances=instances)) + ) + + def instance_from_time_dimension_grain_and_date_part( + self, time_dimension_spec: TimeDimensionSpec + ) -> TimeDimensionInstance: + """Find instance in dataset that matches the grain and date part of the given time dimension spec.""" + for time_dimension_instance in self.instance_set.time_dimension_instances: + if ( + time_dimension_instance.spec.time_granularity == time_dimension_spec.time_granularity + and time_dimension_instance.spec.date_part == time_dimension_spec.date_part + ): + return time_dimension_instance + + raise RuntimeError( + f"Did not find a time dimension instance with matching grain and date part for spec: {time_dimension_spec}\n" + f"Instances available: {self.instance_set.time_dimension_instances}" + ) + def column_association_for_time_dimension(self, time_dimension_spec: TimeDimensionSpec) -> ColumnAssociation: """Given the name of the time dimension, return the set of columns associated with it in the data set.""" return self.instance_for_time_dimension(time_dimension_spec).associated_column diff --git a/metricflow/execution/dataflow_to_execution.py b/metricflow/execution/dataflow_to_execution.py index fa0518e847..b5369f7350 100644 --- a/metricflow/execution/dataflow_to_execution.py +++ b/metricflow/execution/dataflow_to_execution.py @@ -12,6 +12,7 @@ from metricflow.dataflow.dataflow_plan_visitor import DataflowPlanNodeVisitor from metricflow.dataflow.nodes.add_generated_uuid import AddGeneratedUuidColumnNode from metricflow.dataflow.nodes.aggregate_measures import AggregateMeasuresNode +from metricflow.dataflow.nodes.alias_specs import AliasSpecsNode from metricflow.dataflow.nodes.combine_aggregated_outputs import CombineAggregatedOutputsNode from metricflow.dataflow.nodes.compute_metrics import ComputeMetricsNode from metricflow.dataflow.nodes.constrain_time import ConstrainTimeRangeNode @@ -200,3 +201,7 @@ def visit_join_conversion_events_node(self, node: JoinConversionEventsNode) -> C @override def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNode) -> ConvertToExecutionPlanResult: raise NotImplementedError + + @override + def visit_alias_specs_node(self, node: AliasSpecsNode) -> ConvertToExecutionPlanResult: + raise NotImplementedError diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index 96688e629f..18bff46afa 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -51,6 +51,7 @@ from metricflow.dataflow.dataflow_plan_visitor import DataflowPlanNodeVisitor from metricflow.dataflow.nodes.add_generated_uuid import AddGeneratedUuidColumnNode from metricflow.dataflow.nodes.aggregate_measures import AggregateMeasuresNode +from metricflow.dataflow.nodes.alias_specs import AliasSpecsNode from metricflow.dataflow.nodes.combine_aggregated_outputs import CombineAggregatedOutputsNode from metricflow.dataflow.nodes.compute_metrics import ComputeMetricsNode from metricflow.dataflow.nodes.constrain_time import ConstrainTimeRangeNode @@ -313,6 +314,7 @@ def _next_unique_table_alias(self) -> str: """Return the next unique table alias to use in generating queries.""" return SequentialIdGenerator.create_next_id(StaticIdPrefix.SUB_QUERY).str_value + # TODO: replace this with a dataflow plan node for cumulative metrics def _make_time_spine_data_set( self, agg_time_dimension_instances: Tuple[TimeDimensionInstance, ...], @@ -1372,97 +1374,72 @@ def _choose_instance_for_time_spine_join( def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet: # noqa: D102 parent_data_set = node.parent_node.accept(self) parent_alias = self._next_unique_table_alias() - - agg_time_dimension_instances = parent_data_set.instances_for_time_dimensions( - node.requested_agg_time_dimension_specs - ) - - # Select the dimension for the join from the parent node because it may not have been included in the request. - # Default to using metric_time for the join if it was requested, otherwise use the agg_time_dimension. - included_metric_time_instances = [ - instance for instance in agg_time_dimension_instances if instance.spec.is_metric_time - ] - if included_metric_time_instances: - join_on_time_dimension_sample = included_metric_time_instances[0].spec - else: - join_on_time_dimension_sample = agg_time_dimension_instances[0].spec - agg_time_dimension_instance_for_join = self._choose_instance_for_time_spine_join( - [ - instance - for instance in parent_data_set.instance_set.time_dimension_instances - if instance.spec.element_name == join_on_time_dimension_sample.element_name - and instance.spec.entity_links == join_on_time_dimension_sample.entity_links - ] - ) - if agg_time_dimension_instance_for_join not in agg_time_dimension_instances: - agg_time_dimension_instances = (agg_time_dimension_instance_for_join,) + agg_time_dimension_instances - - # Build time spine data set with just the agg_time_dimension instance needed for the join. + time_spine_data_set = node.time_spine_node.accept(self) time_spine_alias = self._next_unique_table_alias() - time_spine_dataset = self._make_time_spine_data_set( - agg_time_dimension_instances=agg_time_dimension_instances, - time_range_constraint=node.time_range_constraint, - time_spine_where_constraints=node.time_spine_filters or (), - ) + + required_agg_time_dimension_specs = tuple(node.requested_agg_time_dimension_specs) + if node.join_on_time_dimension_spec not in node.requested_agg_time_dimension_specs: + required_agg_time_dimension_specs += (node.join_on_time_dimension_spec,) # Build join expression. + join_column_name = self._column_association_resolver.resolve_spec(node.join_on_time_dimension_spec).column_name join_description = SqlQueryPlanJoinBuilder.make_join_to_time_spine_join_description( node=node, time_spine_alias=time_spine_alias, - agg_time_dimension_column_name=self._column_association_resolver.resolve_spec( - agg_time_dimension_instance_for_join.spec - ).column_name, + agg_time_dimension_column_name=join_column_name, parent_sql_select_node=parent_data_set.checked_sql_select_node, parent_alias=parent_alias, ) - # Remove time spine instances from parent instance set. - time_spine_instances = time_spine_dataset.instance_set - time_spine_specs = time_spine_instances.spec_set - parent_instance_set = parent_data_set.instance_set.transform(FilterElements(exclude_specs=time_spine_specs)) + # Build combined instance set. + time_spine_required_spec_set = InstanceSpecSet(time_dimension_specs=required_agg_time_dimension_specs) + parent_instance_set = parent_data_set.instance_set.transform( + FilterElements(exclude_specs=time_spine_required_spec_set) + ) + time_spine_instance_set = time_spine_data_set.instance_set.transform( + FilterElements(include_specs=time_spine_required_spec_set) + ) + output_instance_set = InstanceSet.merge([parent_instance_set, time_spine_instance_set]) - # Build select columns + # Build new simple select columns. select_columns = create_simple_select_columns_for_instance_sets( self._column_association_resolver, - OrderedDict({parent_alias: parent_instance_set, time_spine_alias: time_spine_dataset.instance_set}), + OrderedDict({parent_alias: parent_instance_set, time_spine_alias: time_spine_instance_set}), ) # If offset_to_grain is used, will need to filter down to rows that match selected granularities. # Does not apply if one of the granularities selected matches the time spine column granularity. where_filter: Optional[SqlExpressionNode] = None need_where_filter = ( - node.offset_to_grain - and agg_time_dimension_instance_for_join.spec not in node.requested_agg_time_dimension_specs + node.offset_to_grain and node.join_on_time_dimension_spec not in node.requested_agg_time_dimension_specs ) + + # Filter down to one row per granularity period requested in the group by. Any other granularities + # included here will be filtered out before aggregation and so should not be included in where filter. if need_where_filter: join_column_expr = SqlColumnReferenceExpression.from_table_and_column_names( - table_alias=time_spine_alias, - column_name=agg_time_dimension_instance_for_join.associated_column.column_name, + table_alias=time_spine_alias, column_name=join_column_name ) - for time_spine_instance in time_spine_instances.as_tuple: - # Filter down to one row per granularity period requested in the group by. Any other granularities - # included here will be filtered out in later nodes so should not be included in where filter. - if need_where_filter and time_spine_instance.spec in node.requested_agg_time_dimension_specs: - column_to_filter_expr = SqlColumnReferenceExpression.from_table_and_column_names( - table_alias=time_spine_alias, column_name=time_spine_instance.associated_column.column_name - ) - new_where_filter = SqlComparisonExpression.create( - left_expr=column_to_filter_expr, comparison=SqlComparison.EQUALS, right_expr=join_column_expr - ) - where_filter = ( - SqlLogicalExpression.create( - operator=SqlLogicalOperator.OR, args=(where_filter, new_where_filter) - ) - if where_filter - else new_where_filter - ) + for requested_spec in node.requested_agg_time_dimension_specs: + column_name = self._column_association_resolver.resolve_spec(requested_spec).column_name + column_to_filter_expr = SqlColumnReferenceExpression.from_table_and_column_names( + table_alias=time_spine_alias, column_name=column_name + ) + new_where_filter = SqlComparisonExpression.create( + left_expr=column_to_filter_expr, comparison=SqlComparison.EQUALS, right_expr=join_column_expr + ) + where_filter = ( + SqlLogicalExpression.create(operator=SqlLogicalOperator.OR, args=(where_filter, new_where_filter)) + if where_filter + else new_where_filter + ) return SqlDataSet( - instance_set=InstanceSet.merge([time_spine_dataset.instance_set, parent_instance_set]), + instance_set=output_instance_set, sql_select_node=SqlSelectStatementNode.create( description=node.description, select_columns=select_columns, - from_source=time_spine_dataset.checked_sql_select_node, + from_source=time_spine_data_set.checked_sql_select_node, from_source_alias=time_spine_alias, join_descs=(join_description,), where=where_filter, @@ -1487,6 +1464,60 @@ def _get_custom_granularity_column_name(self, custom_granularity_name: str) -> s f"Custom granularity {custom_granularity} not found. This indicates internal misconfiguration." ) + def visit_alias_specs_node(self, node: AliasSpecsNode) -> SqlDataSet: # noqa: D102 + parent_data_set = node.parent_node.accept(self) + parent_alias = self._next_unique_table_alias() + + new_instances: Tuple[MdoInstance, ...] = () + new_select_columns: Tuple[SqlSelectColumn, ...] = () + instances_to_remove_from_parent: Set[MdoInstance] = set() + for spec_to_alias in node.change_specs: + old_spec = spec_to_alias.input_spec + new_spec = spec_to_alias.output_spec + + # Find the instance in the parent data set with matching grain & date part. + old_instance = parent_data_set.instance_for_spec(old_spec) + + # Build new instance & select column to match requested spec. + new_instance = old_instance.with_new_spec( + new_spec=new_spec, column_association_resolver=self._column_association_resolver + ) + new_expr = SqlColumnReferenceExpression.from_table_and_column_names( + table_alias=parent_alias, column_name=old_instance.associated_column.column_name + ) + new_select_column = SqlSelectColumn(expr=new_expr, column_alias=new_instance.associated_column.column_name) + instances_to_remove_from_parent.add(old_instance) + new_instances += (new_instance,) + new_select_columns += (new_select_column,) + + # Build full output instance set. + filtered_parent_instance_set = group_instances_by_type( + tuple( + instance + for instance in parent_data_set.instance_set.as_tuple + if instance not in instances_to_remove_from_parent + ) + ) + new_instance_set = group_instances_by_type(new_instances) + transformed_instance_set = InstanceSet.merge([filtered_parent_instance_set, new_instance_set]) + + # Build final select columns. + filtered_parent_select_columns = create_simple_select_columns_for_instance_sets( + column_resolver=self._column_association_resolver, + table_alias_to_instance_set=OrderedDict({parent_alias: filtered_parent_instance_set}), + ) + transformed_select_columns = new_select_columns + filtered_parent_select_columns + + return SqlDataSet( + instance_set=transformed_instance_set, + sql_select_node=SqlSelectStatementNode.create( + description=node.description, + select_columns=transformed_select_columns, + from_source=parent_data_set.checked_sql_select_node, + from_source_alias=parent_alias, + ), + ) + def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNode) -> SqlDataSet: # noqa: D102 parent_data_set = node.parent_node.accept(self) @@ -2114,5 +2145,9 @@ def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNod node=node, node_to_select_subquery_function=super().visit_join_to_custom_granularity_node ) + @override + def visit_alias_specs_node(self, node: AliasSpecsNode) -> SqlDataSet: # noqa: D102 + return self._default_handler(node=node, node_to_select_subquery_function=super().visit_alias_specs_node) + DataflowNodeT = TypeVar("DataflowNodeT", bound=DataflowPlanNode) diff --git a/metricflow/plan_conversion/node_processor.py b/metricflow/plan_conversion/node_processor.py index 19ce50acfe..bbeca250c0 100644 --- a/metricflow/plan_conversion/node_processor.py +++ b/metricflow/plan_conversion/node_processor.py @@ -622,7 +622,7 @@ def remove_unnecessary_nodes( desired_linkable_specs: Sequence[LinkableInstanceSpec], nodes: Sequence[DataflowPlanNode], metric_time_dimension_reference: TimeDimensionReference, - time_spine_nodes: Sequence[MetricTimeDimensionTransformNode], + time_spine_metric_time_nodes: Sequence[MetricTimeDimensionTransformNode], ) -> List[DataflowPlanNode]: """Filters out many of the nodes that can't possibly be useful for joins to obtain the desired linkable specs. @@ -668,7 +668,7 @@ def remove_unnecessary_nodes( continue # Used for group-by-item-values queries. - if node in time_spine_nodes: + if node in time_spine_metric_time_nodes: logger.debug(LazyFormat(lambda: f"Including {node} since it matches `time_spine_node`")) relevant_nodes.append(node) continue diff --git a/tests_metricflow/dataflow/builder/test_node_evaluator.py b/tests_metricflow/dataflow/builder/test_node_evaluator.py index 20d932421d..f4785806e4 100644 --- a/tests_metricflow/dataflow/builder/test_node_evaluator.py +++ b/tests_metricflow/dataflow/builder/test_node_evaluator.py @@ -49,7 +49,7 @@ def node_evaluator( ].semantic_manifest_lookup.semantic_model_lookup, nodes_available_for_joins=tuple(mf_engine_fixture.read_node_mapping.values()), node_data_set_resolver=node_data_set_resolver, - time_spine_nodes=mf_engine_fixture.source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=mf_engine_fixture.source_node_set.time_spine_metric_time_nodes_tuple, ) @@ -73,7 +73,7 @@ def make_multihop_node_evaluator( desired_linkable_specs=desired_linkable_specs, nodes=source_node_set.source_nodes_for_metric_queries, metric_time_dimension_reference=DataSet.metric_time_dimension_reference(), - time_spine_nodes=source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=source_node_set.time_spine_metric_time_nodes_tuple, ) nodes_available_for_joins = list( @@ -88,7 +88,7 @@ def make_multihop_node_evaluator( semantic_model_lookup=semantic_manifest_lookup_with_multihop_links.semantic_model_lookup, nodes_available_for_joins=nodes_available_for_joins, node_data_set_resolver=node_data_set_resolver, - time_spine_nodes=source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=source_node_set.time_spine_metric_time_nodes_tuple, ) @@ -521,7 +521,7 @@ def test_node_evaluator_with_scd_target( # Use all nodes in the simple model as candidates for joins. nodes_available_for_joins=tuple(mf_engine_fixture.read_node_mapping.values()), node_data_set_resolver=node_data_set_resolver, - time_spine_nodes=mf_engine_fixture.source_node_set.time_spine_nodes_tuple, + time_spine_metric_time_nodes=mf_engine_fixture.source_node_set.time_spine_metric_time_nodes_tuple, ) evaluation = node_evaluator.evaluate_node( diff --git a/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py b/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py index 01143c4c18..05770806a0 100644 --- a/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py +++ b/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py @@ -20,6 +20,7 @@ from metricflow.dataflow.dataflow_plan_visitor import DataflowPlanNodeVisitor from metricflow.dataflow.nodes.add_generated_uuid import AddGeneratedUuidColumnNode from metricflow.dataflow.nodes.aggregate_measures import AggregateMeasuresNode +from metricflow.dataflow.nodes.alias_specs import AliasSpecsNode from metricflow.dataflow.nodes.combine_aggregated_outputs import CombineAggregatedOutputsNode from metricflow.dataflow.nodes.compute_metrics import ComputeMetricsNode from metricflow.dataflow.nodes.constrain_time import ConstrainTimeRangeNode @@ -110,6 +111,9 @@ def visit_join_conversion_events_node(self, node: JoinConversionEventsNode) -> i def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNode) -> int: # noqa: D102 return self._sum_parents(node) + def visit_alias_specs_node(self, node: AliasSpecsNode) -> int: # noqa: D102 + return self._sum_parents(node) + def count_source_nodes(self, dataflow_plan: DataflowPlan) -> int: # noqa: D102 return dataflow_plan.sink_node.accept(self) diff --git a/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py b/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py index b2e22ce13d..9cb93184b3 100644 --- a/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py +++ b/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py @@ -295,3 +295,65 @@ def test_join_to_time_spine_with_custom_grain_in_group_by( # noqa: D103 snapshot_str=query_result.result_df.text_format(), sql_engine=sql_client.sql_engine_type, ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_timespine_metric_with_custom_granularity_filter( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + sql_client: SqlClient, + it_helpers: IntegrationTestHelpers, +) -> None: + if sql_client.sql_engine_type is SqlEngine.TRINO: + pytest.skip( + "Trino does not support the syntax used in this where filter, but it can't be made engine-agnostic." + ) + + query_result = it_helpers.mf_engine.query( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=("bookings_join_to_time_spine",), + group_by_names=("metric_time__martian_day",), + order_by_names=("metric_time__martian_day",), + where_constraints=["{{ TimeDimension('metric_time', 'martian_day') }} = '2020-01-08'"], + ) + ) + assert query_result.result_df is not None, "Unexpected empty result." + + assert_str_snapshot_equal( + request=request, + mf_test_configuration=mf_test_configuration, + snapshot_id="query_output", + snapshot_str=query_result.result_df.text_format(), + sql_engine=sql_client.sql_engine_type, + ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + sql_client: SqlClient, + it_helpers: IntegrationTestHelpers, +) -> None: + if sql_client.sql_engine_type is SqlEngine.TRINO: + pytest.skip( + "Trino does not support the syntax used in this where filter, but it can't be made engine-agnostic." + ) + + query_result = it_helpers.mf_engine.query( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=("bookings_join_to_time_spine",), + group_by_names=("metric_time__day",), + order_by_names=("metric_time__day",), + where_constraints=["{{ TimeDimension('metric_time', 'martian_day') }} = '2020-01-08'"], + ) + ) + assert query_result.result_df is not None, "Unexpected empty result." + + assert_str_snapshot_equal( + request=request, + mf_test_configuration=mf_test_configuration, + snapshot_id="query_output", + snapshot_str=query_result.result_df.text_format(), + sql_engine=sql_client.sql_engine_type, + ) diff --git a/tests_metricflow/query_rendering/test_custom_granularity.py b/tests_metricflow/query_rendering/test_custom_granularity.py index 07823f07b1..4043c7b97d 100644 --- a/tests_metricflow/query_rendering/test_custom_granularity.py +++ b/tests_metricflow/query_rendering/test_custom_granularity.py @@ -556,3 +556,57 @@ def test_join_to_time_spine_metric_grouped_by_custom_grain( # noqa: D103 dataflow_plan_builder=dataflow_plan_builder, query_spec=query_spec, ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_timespine_metric_with_custom_granularity_filter( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, + query_parser: MetricFlowQueryParser, +) -> None: + query_spec = query_parser.parse_and_validate_query( + metric_names=("bookings_join_to_time_spine",), + group_by_names=("metric_time__martian_day",), + where_constraints=[ + PydanticWhereFilter(where_sql_template=("{{ TimeDimension('metric_time', 'martian_day') }} = '2020-01-01'")) + ], + ).query_spec + + render_and_check( + request=request, + mf_test_configuration=mf_test_configuration, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + dataflow_plan_builder=dataflow_plan_builder, + query_spec=query_spec, + ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, + query_parser: MetricFlowQueryParser, +) -> None: + query_spec = query_parser.parse_and_validate_query( + metric_names=("bookings_join_to_time_spine",), + group_by_names=("metric_time__day",), + where_constraints=[ + PydanticWhereFilter(where_sql_template=("{{ TimeDimension('metric_time', 'martian_day') }} = '2020-01-01'")) + ], + ).query_spec + + render_and_check( + request=request, + mf_test_configuration=mf_test_configuration, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + dataflow_plan_builder=dataflow_plan_builder, + query_spec=query_spec, + ) 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 bdc55673da..a61539bd22 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -120,115 +152,147 @@ 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 ( + -- Change Column Aliases + SELECT + subq_18.ds__day AS metric_time__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__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_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 +327,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 +484,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 c29b49ee48..04e97e0af2 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 618e405f07..6cad57ff60 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -120,115 +152,147 @@ 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 ( + -- Change Column Aliases + SELECT + subq_18.ds__day AS metric_time__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__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_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 +327,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 +484,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 054eabc223..388b9302b7 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/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql index f0cde24ff7..0640226e4d 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.sql @@ -6,25 +6,57 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_20.metric_time__day - , CAST(subq_20.buys AS DOUBLE) / CAST(NULLIF(subq_20.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 + subq_22.metric_time__day + , CAST(subq_22.buys AS DOUBLE) / CAST(NULLIF(subq_22.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days_fill_nulls_with_0 FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_19.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_6.visits), 0) AS visits - , COALESCE(MAX(subq_19.buys), 0) AS buys + COALESCE(subq_7.metric_time__day, subq_21.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_7.visits), 0) AS visits + , COALESCE(MAX(subq_21.buys), 0) AS buys FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.visits AS visits FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -120,115 +152,147 @@ 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 ( + -- Change Column Aliases + SELECT + subq_18.ds__day AS metric_time__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__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_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 +327,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 +484,30 @@ FROM ( , buys_source_src_28000.user_id AS buy__user , buys_source_src_28000.session_id AS buy__session_id FROM ***************************.fct_buys buys_source_src_28000 - ) subq_10 - ) subq_11 - ) subq_12 + ) subq_11 + ) subq_12 + ) subq_13 ON ( - subq_9.user = subq_12.user + subq_10.user = subq_13.user ) AND ( ( - subq_9.metric_time__day <= subq_12.metric_time__day + subq_10.metric_time__day <= subq_13.metric_time__day ) AND ( - subq_9.metric_time__day > subq_12.metric_time__day - INTERVAL 7 day + subq_10.metric_time__day > subq_13.metric_time__day - INTERVAL 7 day ) ) - ) subq_13 - ) subq_14 - ) subq_15 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY - subq_15.metric_time__day - ) subq_16 + subq_16.metric_time__day + ) subq_17 ON - subq_17.metric_time__day = subq_16.metric_time__day - ) subq_19 + subq_20.metric_time__day = subq_17.metric_time__day + ) subq_21 ON - subq_6.metric_time__day = subq_19.metric_time__day + subq_7.metric_time__day = subq_21.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_19.metric_time__day) -) subq_20 + COALESCE(subq_7.metric_time__day, subq_21.metric_time__day) +) subq_22 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql index f93bee27a4..1bab2d34dc 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0_optimized.sql @@ -21,15 +21,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_27.metric_time__day, subq_39.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_27.visits), 0) AS visits - , COALESCE(MAX(subq_39.buys), 0) AS buys + COALESCE(subq_30.metric_time__day, subq_43.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_30.visits), 0) AS visits + , COALESCE(MAX(subq_43.buys), 0) AS buys FROM ( -- Join to Time Spine Dataset SELECT - subq_26.ds AS metric_time__day - , subq_24.visits AS visits - FROM ***************************.mf_time_spine subq_26 + time_spine_src_28006.ds AS metric_time__day + , subq_26.visits AS visits + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Read From CTE For node_id=sma_28019 -- Pass Only Elements: ['visits', 'metric_time__day'] @@ -40,16 +40,16 @@ FROM ( FROM sma_28019_cte sma_28019_cte GROUP BY metric_time__day - ) subq_24 + ) subq_26 ON - subq_26.ds = subq_24.metric_time__day - ) subq_27 + time_spine_src_28006.ds = subq_26.metric_time__day + ) subq_30 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - subq_38.ds AS metric_time__day - , subq_36.buys AS buys - FROM ***************************.mf_time_spine subq_38 + time_spine_src_28006.ds AS metric_time__day + , subq_39.buys AS buys + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -62,30 +62,30 @@ FROM ( SELECT DISTINCT FIRST_VALUE(sma_28019_cte.visits) OVER ( PARTITION BY - subq_32.user - , subq_32.metric_time__day - , subq_32.mf_internal_uuid + subq_35.user + , subq_35.metric_time__day + , subq_35.mf_internal_uuid ORDER BY sma_28019_cte.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits , FIRST_VALUE(sma_28019_cte.metric_time__day) OVER ( PARTITION BY - subq_32.user - , subq_32.metric_time__day - , subq_32.mf_internal_uuid + subq_35.user + , subq_35.metric_time__day + , subq_35.mf_internal_uuid ORDER BY sma_28019_cte.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day , FIRST_VALUE(sma_28019_cte.user) OVER ( PARTITION BY - subq_32.user - , subq_32.metric_time__day - , subq_32.mf_internal_uuid + subq_35.user + , subq_35.metric_time__day + , subq_35.mf_internal_uuid ORDER BY sma_28019_cte.metric_time__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_32.mf_internal_uuid AS mf_internal_uuid - , subq_32.buys AS buys + , subq_35.mf_internal_uuid AS mf_internal_uuid + , subq_35.buys AS buys FROM sma_28019_cte sma_28019_cte INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' @@ -97,26 +97,26 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_32 + ) subq_35 ON ( - sma_28019_cte.user = subq_32.user + sma_28019_cte.user = subq_35.user ) AND ( ( - sma_28019_cte.metric_time__day <= subq_32.metric_time__day + sma_28019_cte.metric_time__day <= subq_35.metric_time__day ) AND ( - sma_28019_cte.metric_time__day > subq_32.metric_time__day - INTERVAL 7 day + sma_28019_cte.metric_time__day > subq_35.metric_time__day - INTERVAL 7 day ) ) - ) subq_33 + ) subq_36 GROUP BY metric_time__day - ) subq_36 + ) subq_39 ON - subq_38.ds = subq_36.metric_time__day - ) subq_39 + time_spine_src_28006.ds = subq_39.metric_time__day + ) subq_43 ON - subq_27.metric_time__day = subq_39.metric_time__day + subq_30.metric_time__day = subq_43.metric_time__day GROUP BY - COALESCE(subq_27.metric_time__day, subq_39.metric_time__day) -) subq_40 + COALESCE(subq_30.metric_time__day, subq_43.metric_time__day) +) subq_44 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/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 47de6c7fea..2a4b650fbc 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -120,115 +152,147 @@ 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 ( + -- Change Column Aliases + SELECT + subq_18.ds__day AS metric_time__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__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_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 +327,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 +484,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 ed86788422..cd6c238dc3 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 a6ad786a7b..88bdf8dede 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -120,115 +152,147 @@ 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 ( + -- Change Column Aliases + SELECT + subq_18.ds__day AS metric_time__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__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_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 +327,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 +484,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 3c41d84dcb..b7de22a306 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 83fdc354a2..6966b1ea30 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -120,115 +152,147 @@ 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 ( + -- Change Column Aliases + SELECT + subq_18.ds__day AS metric_time__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__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_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 +327,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 +484,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 463efd3a56..3e17a6cacb 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 10cab4b4e1..86ecc444c0 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -120,115 +152,147 @@ 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 ( + -- Change Column Aliases + SELECT + subq_18.ds__day AS metric_time__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__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_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 +327,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 +484,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 b354a8d965..9224c66d0e 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_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml index 352d701da6..50b2f52859 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml @@ -6,19 +6,19 @@ docstring: - - + + - + - + @@ -34,11 +34,11 @@ docstring: - + - - + + @@ -51,14 +51,14 @@ docstring: - + - - - + + + - + @@ -66,25 +66,144 @@ docstring: - - + + - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -95,7 +214,7 @@ docstring: - + @@ -105,7 +224,7 @@ docstring: - + @@ -113,12 +232,12 @@ docstring: - + - + @@ -318,12 +437,12 @@ docstring: - + - + @@ -489,43 +608,165 @@ docstring: - + - - - + + + - - + + - - + + - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -533,50 +774,50 @@ docstring: - + - + - + - + - - + + - + - + - + - + - + - + - + @@ -594,19 +835,19 @@ docstring: - + - + - + - - + + @@ -614,239 +855,239 @@ docstring: - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + - + - + - + - + - + @@ -1010,260 +1251,260 @@ docstring: - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1271,273 +1512,273 @@ docstring: - + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - + + + + + + + + + + + - + 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 01f3d2d54b..d34c8f316d 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,75 @@ 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 ( + -- Change Column Aliases + 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__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -377,10 +409,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 76197cdbcc..2773539027 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 dc03b367c6..460a9a1f96 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,75 @@ 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 ( + -- Change Column Aliases + 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__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -377,11 +409,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 4a16253b66..9a4804c24e 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/DuckDB/test_window_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql index 8e1e4d0e93..b8dee179a7 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0.sql @@ -8,43 +8,75 @@ sql_engine: DuckDB --- -- Re-aggregate Metric via Group By SELECT - subq_11.booking__ds__month - , subq_11.metric_time__week - , subq_11.every_two_days_bookers_fill_nulls_with_0 + subq_12.booking__ds__month + , subq_12.metric_time__week + , subq_12.every_two_days_bookers_fill_nulls_with_0 FROM ( -- Window Function for Metric Re-aggregation SELECT - subq_10.booking__ds__month - , subq_10.metric_time__week - , FIRST_VALUE(subq_10.every_two_days_bookers_fill_nulls_with_0) OVER ( + subq_11.booking__ds__month + , subq_11.metric_time__week + , FIRST_VALUE(subq_11.every_two_days_bookers_fill_nulls_with_0) OVER ( PARTITION BY - subq_10.booking__ds__month - , subq_10.metric_time__week - ORDER BY subq_10.metric_time__day + subq_11.booking__ds__month + , subq_11.metric_time__week + ORDER BY subq_11.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS every_two_days_bookers_fill_nulls_with_0 FROM ( -- Compute Metrics via Expressions SELECT - subq_9.booking__ds__month - , subq_9.metric_time__day - , subq_9.metric_time__week - , COALESCE(subq_9.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 + subq_10.booking__ds__month + , subq_10.metric_time__week + , subq_10.metric_time__day + , COALESCE(subq_10.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_7.booking__ds__month AS booking__ds__month - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__week AS metric_time__week + subq_9.booking__ds__month AS booking__ds__month + , subq_9.metric_time__week AS metric_time__week + , subq_9.metric_time__day AS metric_time__day , subq_6.bookers AS bookers FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['booking__ds__month', 'metric_time__week', 'metric_time__day'] SELECT - DATE_TRUNC('month', subq_8.ds) AS booking__ds__month - , subq_8.ds AS metric_time__day - , DATE_TRUNC('week', subq_8.ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.booking__ds__month + , subq_8.metric_time__week + , subq_8.metric_time__day + FROM ( + -- Change Column Aliases + 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__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -377,11 +409,11 @@ FROM ( , subq_5.metric_time__week ) subq_6 ON - subq_7.metric_time__day = subq_6.metric_time__day - ) subq_9 - ) subq_10 -) subq_11 + subq_9.metric_time__day = subq_6.metric_time__day + ) subq_10 + ) subq_11 +) subq_12 GROUP BY - subq_11.booking__ds__month - , subq_11.metric_time__week - , subq_11.every_two_days_bookers_fill_nulls_with_0 + subq_12.booking__ds__month + , subq_12.metric_time__week + , subq_12.every_two_days_bookers_fill_nulls_with_0 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql index 3e431cfda5..e22a6a6837 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grains__plan0_optimized.sql @@ -27,38 +27,38 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('month', subq_20.ds) AS booking__ds__month - , subq_20.ds AS metric_time__day - , DATE_TRUNC('week', subq_20.ds) AS metric_time__week - , subq_18.bookers AS bookers - FROM ***************************.mf_time_spine subq_20 + DATE_TRUNC('month', time_spine_src_28006.ds) AS booking__ds__month + , DATE_TRUNC('week', time_spine_src_28006.ds) AS metric_time__week + , time_spine_src_28006.ds AS metric_time__day + , subq_19.bookers AS bookers + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] -- Aggregate Measures SELECT - DATE_TRUNC('month', subq_15.ds) AS booking__ds__month - , subq_15.ds AS metric_time__day - , DATE_TRUNC('week', subq_15.ds) AS metric_time__week + DATE_TRUNC('month', subq_16.ds) AS booking__ds__month + , subq_16.ds AS metric_time__day + , DATE_TRUNC('week', subq_16.ds) AS metric_time__week , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine subq_16 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_16.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_16.ds - INTERVAL 2 day ) GROUP BY - DATE_TRUNC('month', subq_15.ds) - , subq_15.ds - , DATE_TRUNC('week', subq_15.ds) - ) subq_18 + DATE_TRUNC('month', subq_16.ds) + , subq_16.ds + , DATE_TRUNC('week', subq_16.ds) + ) subq_19 ON - subq_20.ds = subq_18.metric_time__day - ) subq_21 -) subq_23 + time_spine_src_28006.ds = subq_19.metric_time__day + ) subq_23 +) subq_25 GROUP BY booking__ds__month , metric_time__week diff --git a/tests_metricflow/snapshots/test_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 70d14c500d..148fc930cb 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,75 @@ 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 ( + -- Change Column Aliases + 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__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -377,11 +409,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 417844f92d..983a2828ca 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 941471bd80..b8b61ce77d 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,75 @@ 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 ( + -- Change Column Aliases + 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__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -377,11 +409,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 5d172a21ac..48882b6b0c 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 227ad2b2be..9b5d199cb0 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,75 @@ 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 ( + -- Change Column Aliases + 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__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -377,11 +409,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 d98ee20cf1..4a5e31a4fc 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 f3f6aceedc..a895385e11 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,75 @@ 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 ( + -- Change Column Aliases + 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__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -377,11 +409,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 aa9a15b723..86b0938c51 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 f86e3584ba..f5c717f0e4 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__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 + 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 +267,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 0f8e2275d2..aec1f58f68 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' + -- Change Column Aliases + -- 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 0000000000..0cf0886a44 --- /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,392 @@ +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__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.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__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 + 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 0000000000..688a8a4cc3 --- /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' + -- Change Column Aliases + 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 0000000000..318501924a --- /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,390 @@ +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__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.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_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 + 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 0000000000..46e6d3d400 --- /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' + -- Change Column Aliases + 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_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 26d09dbf61..dd363fffeb 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -326,14 +358,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 ac6a6b2162..56fd02c5dc 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 5f8af4c9a3..3af790768f 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,16 +460,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 4239dbf288..c2d381e942 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 9f446138a9..18a5d12a01 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 +267,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 aca2005c25..662007d156 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' + -- Change Column Aliases + -- 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 0000000000..78e1b6c1ba --- /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,392 @@ +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__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.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 0000000000..59a7a6280c --- /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' + -- Change Column Aliases + 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 0000000000..62557cf252 --- /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,390 @@ +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__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.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 0000000000..e165d41366 --- /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' + -- Change Column Aliases + 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_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 11069c83b1..36ad1a6ad1 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -326,14 +358,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 cc3c8aeff5..b083f7d8fd 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 2b8e2f9a4c..dbb7f8f76c 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,16 +460,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 e4cb94adb0..f72023cccd 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/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql index 3b2fd22074..c97759a07c 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0.sql @@ -4,21 +4,53 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__martian_day - , subq_7.bookings AS bookings_join_to_time_spine + subq_8.metric_time__martian_day + , subq_8.bookings AS bookings_join_to_time_spine FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__martian_day AS metric_time__martian_day + subq_7.metric_time__martian_day AS metric_time__martian_day , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__martian_day',] SELECT - subq_6.martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_6 + subq_6.metric_time__martian_day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 +267,5 @@ FROM ( subq_3.metric_time__martian_day ) subq_4 ON - subq_5.metric_time__martian_day = subq_4.metric_time__martian_day -) subq_7 + subq_7.metric_time__martian_day = subq_4.metric_time__martian_day +) subq_8 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql index 2b21a9d62e..cdcc9a1e05 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_metric_grouped_by_custom_grain__plan0_optimized.sql @@ -5,37 +5,39 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_13.metric_time__martian_day AS metric_time__martian_day - , subq_12.bookings AS bookings_join_to_time_spine + subq_16.metric_time__martian_day AS metric_time__martian_day + , subq_13.bookings AS bookings_join_to_time_spine FROM ( -- Read From Time Spine 'mf_time_spine' + -- Change Column Aliases + -- Pass Only Elements: ['metric_time__martian_day',] SELECT martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY martian_day -) subq_13 +) subq_16 LEFT OUTER JOIN ( -- Metric Time Dimension 'ds' -- Join to Custom Granularity Dataset -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] -- Aggregate Measures SELECT - subq_9.martian_day AS metric_time__martian_day - , SUM(subq_8.bookings) AS bookings + subq_10.martian_day AS metric_time__martian_day + , SUM(subq_9.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT 1 AS bookings , DATE_TRUNC('day', ds) AS ds__day FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 + ) subq_9 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_10 ON - subq_8.ds__day = subq_9.ds + subq_9.ds__day = subq_10.ds GROUP BY - subq_9.martian_day -) subq_12 + subq_10.martian_day +) subq_13 ON - subq_13.metric_time__martian_day = subq_12.metric_time__martian_day + subq_16.metric_time__martian_day = subq_13.metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql new file mode 100644 index 0000000000..710baa9d84 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0.sql @@ -0,0 +1,392 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_custom_granularity.py +sql_engine: DuckDB +--- +-- 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__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.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__plan0_optimized.sql new file mode 100644 index 0000000000..9e8d06b1ec --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/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: DuckDB +--- +-- 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' + -- Change Column Aliases + 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/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql new file mode 100644 index 0000000000..156e5cb5e4 --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -0,0 +1,390 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_custom_granularity.py +sql_engine: DuckDB +--- +-- 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__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.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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/DuckDB/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/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql new file mode 100644 index 0000000000..633027ce0b --- /dev/null +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/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: DuckDB +--- +-- 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' + -- Change Column Aliases + 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/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql index 7d92f42a89..148415502e 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.booking__ds__martian_day + subq_9.booking__ds__martian_day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_7.booking__ds__martian_day - , subq_7.bookings AS bookings_5_days_ago + subq_8.booking__ds__martian_day + , subq_8.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_6.booking__ds__martian_day - , SUM(subq_6.bookings) AS bookings + subq_7.booking__ds__martian_day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__ds__martian_day'] SELECT - subq_5.booking__ds__martian_day - , subq_5.bookings + subq_6.booking__ds__martian_day + , subq_6.bookings FROM ( -- Join to Time Spine Dataset -- Join to Custom Granularity Dataset @@ -101,7 +101,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.booking__ds__day AS booking__ds__day + , subq_4.booking__ds__day AS booking__ds__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -123,13 +123,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -326,14 +358,14 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.booking__ds__day - INTERVAL 5 day = subq_1.booking__ds__day + subq_4.booking__ds__day - INTERVAL 5 day = subq_1.booking__ds__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_4 + ***************************.mf_time_spine subq_5 ON - subq_2.booking__ds__day = subq_4.ds - ) subq_5 - ) subq_6 + subq_4.booking__ds__day = subq_5.ds + ) subq_6 + ) subq_7 GROUP BY - subq_6.booking__ds__martian_day - ) subq_7 -) subq_8 + subq_7.booking__ds__martian_day + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql index 9b358e0937..7de34b0ee2 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity__plan0_optimized.sql @@ -13,9 +13,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_13.martian_day AS booking__ds__martian_day - , SUM(subq_10.bookings) AS bookings_5_days_ago - FROM ***************************.mf_time_spine subq_12 + subq_15.martian_day AS booking__ds__martian_day + , SUM(subq_11.bookings) AS bookings_5_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -23,13 +23,13 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - subq_12.ds - INTERVAL 5 day = subq_10.booking__ds__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_11.booking__ds__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_13 + ***************************.mf_time_spine subq_15 ON - subq_12.ds = subq_13.ds + time_spine_src_28006.ds = subq_15.ds GROUP BY - subq_13.martian_day -) subq_17 + subq_15.martian_day +) subq_19 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql index 1a5b634111..20b1277d85 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql @@ -4,125 +4,125 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day + subq_10.metric_time__day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.bookings AS bookings_5_days_ago + subq_9.metric_time__day + , subq_9.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__day - , SUM(subq_7.bookings) AS bookings + subq_8.metric_time__day + , SUM(subq_8.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_7.metric_time__day + , subq_7.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_5.metric_time__martian_day - , subq_5.metric_time__day - , subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.ds_partitioned__day - , subq_5.ds_partitioned__week - , subq_5.ds_partitioned__month - , subq_5.ds_partitioned__quarter - , subq_5.ds_partitioned__year - , subq_5.ds_partitioned__extract_year - , subq_5.ds_partitioned__extract_quarter - , subq_5.ds_partitioned__extract_month - , subq_5.ds_partitioned__extract_day - , subq_5.ds_partitioned__extract_dow - , subq_5.ds_partitioned__extract_doy - , subq_5.paid_at__day - , subq_5.paid_at__week - , subq_5.paid_at__month - , subq_5.paid_at__quarter - , subq_5.paid_at__year - , subq_5.paid_at__extract_year - , subq_5.paid_at__extract_quarter - , subq_5.paid_at__extract_month - , subq_5.paid_at__extract_day - , subq_5.paid_at__extract_dow - , subq_5.paid_at__extract_doy - , subq_5.booking__ds__day - , subq_5.booking__ds__week - , subq_5.booking__ds__month - , subq_5.booking__ds__quarter - , subq_5.booking__ds__year - , subq_5.booking__ds__extract_year - , subq_5.booking__ds__extract_quarter - , subq_5.booking__ds__extract_month - , subq_5.booking__ds__extract_day - , subq_5.booking__ds__extract_dow - , subq_5.booking__ds__extract_doy - , subq_5.booking__ds_partitioned__day - , subq_5.booking__ds_partitioned__week - , subq_5.booking__ds_partitioned__month - , subq_5.booking__ds_partitioned__quarter - , subq_5.booking__ds_partitioned__year - , subq_5.booking__ds_partitioned__extract_year - , subq_5.booking__ds_partitioned__extract_quarter - , subq_5.booking__ds_partitioned__extract_month - , subq_5.booking__ds_partitioned__extract_day - , subq_5.booking__ds_partitioned__extract_dow - , subq_5.booking__ds_partitioned__extract_doy - , subq_5.booking__paid_at__day - , subq_5.booking__paid_at__week - , subq_5.booking__paid_at__month - , subq_5.booking__paid_at__quarter - , subq_5.booking__paid_at__year - , subq_5.booking__paid_at__extract_year - , subq_5.booking__paid_at__extract_quarter - , subq_5.booking__paid_at__extract_month - , subq_5.booking__paid_at__extract_day - , subq_5.booking__paid_at__extract_dow - , subq_5.booking__paid_at__extract_doy - , subq_5.metric_time__week - , subq_5.metric_time__month - , subq_5.metric_time__quarter - , subq_5.metric_time__year - , subq_5.metric_time__extract_year - , subq_5.metric_time__extract_quarter - , subq_5.metric_time__extract_month - , subq_5.metric_time__extract_day - , subq_5.metric_time__extract_dow - , subq_5.metric_time__extract_doy - , subq_5.listing - , subq_5.guest - , subq_5.host - , subq_5.booking__listing - , subq_5.booking__guest - , subq_5.booking__host - , subq_5.is_instant - , subq_5.booking__is_instant - , subq_5.bookings - , subq_5.instant_bookings - , subq_5.booking_value - , subq_5.max_booking_value - , subq_5.min_booking_value - , subq_5.bookers - , subq_5.average_booking_value - , subq_5.referred_bookings - , subq_5.median_booking_value - , subq_5.booking_value_p99 - , subq_5.discrete_booking_value_p99 - , subq_5.approximate_continuous_booking_value_p99 - , subq_5.approximate_discrete_booking_value_p99 + subq_6.metric_time__martian_day + , subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__extract_doy + , subq_6.metric_time__week + , subq_6.metric_time__month + , subq_6.metric_time__quarter + , subq_6.metric_time__year + , subq_6.metric_time__extract_year + , subq_6.metric_time__extract_quarter + , subq_6.metric_time__extract_month + , subq_6.metric_time__extract_day + , subq_6.metric_time__extract_dow + , subq_6.metric_time__extract_doy + , subq_6.metric_time__day + , subq_6.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset -- Join to Custom Granularity Dataset @@ -203,7 +203,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -225,13 +225,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,16 +460,16 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_4 + ***************************.mf_time_spine subq_5 ON - subq_2.metric_time__day = subq_4.ds - ) subq_5 + subq_4.metric_time__day = subq_5.ds + ) subq_6 WHERE metric_time__martian_day = '2020-01-01' - ) subq_6 - ) subq_7 + ) subq_7 + ) subq_8 GROUP BY - subq_7.metric_time__day - ) subq_8 -) subq_9 + subq_8.metric_time__day + ) subq_9 +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql index a74e4042e7..139cbfa160 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql @@ -18,10 +18,10 @@ FROM ( -- Join to Time Spine Dataset -- Join to Custom Granularity Dataset SELECT - subq_13.ds AS metric_time__day - , subq_11.bookings AS bookings - , subq_14.martian_day AS metric_time__martian_day - FROM ***************************.mf_time_spine subq_13 + time_spine_src_28006.ds AS metric_time__day + , subq_12.bookings AS bookings + , subq_16.martian_day AS metric_time__martian_day + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -29,15 +29,15 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + ) subq_12 ON - subq_13.ds - INTERVAL 5 day = subq_11.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_12.metric_time__day LEFT OUTER JOIN - ***************************.mf_time_spine subq_14 + ***************************.mf_time_spine subq_16 ON - subq_13.ds = subq_14.ds - ) subq_15 + time_spine_src_28006.ds = subq_16.ds + ) subq_17 WHERE metric_time__martian_day = '2020-01-01' GROUP BY metric_time__day -) subq_19 +) subq_21 diff --git a/tests_metricflow/snapshots/test_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 45d2f66892..11c4ba0783 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 +267,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 8387f5d46b..fdceb9cf8a 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' + -- Change Column Aliases + -- 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 0000000000..e2a23dff43 --- /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,392 @@ +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__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.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 0000000000..55a29e0c3a --- /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' + -- Change Column Aliases + 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 0000000000..f07c9626f8 --- /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,390 @@ +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__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.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 0000000000..4b80282fb4 --- /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' + -- Change Column Aliases + 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_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 d044519a28..834b5c7745 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -326,14 +358,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 1a03d0f71a..7a645df17d 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 31ea2c71a5..ed4275bd85 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,16 +460,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 e5cb95f9b5..8e795d4a4e 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 d8f039452c..b0493a7319 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , 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 +267,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 bbf4df3583..2d99cb612c 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' + -- Change Column Aliases + -- 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 0000000000..875524e29b --- /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,392 @@ +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__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.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , 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 0000000000..4b943bdf2c --- /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' + -- Change Column Aliases + 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 0000000000..57417cffb6 --- /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,390 @@ +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__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.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , 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 0000000000..4e6c2869ff --- /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' + -- Change Column Aliases + 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_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 77805a6fd5..b546105465 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -326,14 +358,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 70b91bc6a4..6e0433144c 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 a98f058032..6ec746b0f3 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,16 +460,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 40e9bafc5b..c5b00d5129 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 4826683920..48f02fff02 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 +267,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 2cfb7a831c..61940d0dd0 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' + -- Change Column Aliases + -- 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 0000000000..53a3efafdd --- /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,392 @@ +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__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.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 0000000000..a966529c32 --- /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' + -- Change Column Aliases + 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 0000000000..e0b4097b29 --- /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,390 @@ +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__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.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 0000000000..128ef76e45 --- /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' + -- Change Column Aliases + 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_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 f1f3de76b5..dce8e75e51 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -326,14 +358,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 8d106e8686..1ee62fa020 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 520ce10b3d..5ef70929cd 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,16 +460,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 e86c0510f4..758c9edb49 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 071d9ac486..4a8496cf04 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__martian_day AS metric_time__martian_day + , subq_5.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 +267,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 12a7b8a95f..d9454b3ef0 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' + -- Change Column Aliases + -- 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 0000000000..25bd7b0afc --- /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,392 @@ +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__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.metric_time__martian_day + , subq_7.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__martian_day AS metric_time__martian_day + , subq_6.ds__day AS metric_time__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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 0000000000..7f99b60136 --- /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' + -- Change Column Aliases + 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 0000000000..0ded27ae77 --- /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,390 @@ +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__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.metric_time__day + , subq_7.metric_time__martian_day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__martian_day AS metric_time__martian_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 + FROM ( + -- Read From Time Spine 'mf_time_spine' + SELECT + time_spine_src_28006.ds AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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 0000000000..c4eb2e31ce --- /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' + -- Change Column Aliases + 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_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 569610a235..250860a3f6 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -326,14 +358,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 4ab73ec738..3a83a25a26 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 a4430ef8ce..36594c1aa4 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,45 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,16 +460,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 2ed4e1008f..c161c74c5d 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_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml index f8197f144b..895447530c 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_to_grain__dfp_0.xml @@ -60,7 +60,7 @@ docstring: - + @@ -78,6 +78,11 @@ docstring: + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml index fb56aa5dbc..7c4a6e7d13 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_window__dfp_0.xml @@ -26,7 +26,7 @@ docstring: - + @@ -44,6 +44,11 @@ docstring: + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml index d59da00682..89a252d0c3 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_metric_offset_with_granularity__dfp_0.xml @@ -24,7 +24,7 @@ test_filename: test_dataflow_plan_builder.py - + @@ -42,6 +42,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml index d211f448b8..6e835d608e 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_derived_offset_cumulative_metric__dfp_0.xml @@ -25,7 +25,7 @@ test_filename: test_dataflow_plan_builder.py - + @@ -43,6 +43,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml index d9af741338..c28929cd56 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_derived_metric__dfp_0.xml @@ -31,6 +31,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + @@ -79,13 +84,18 @@ test_filename: test_dataflow_plan_builder.py + + + + + - + @@ -103,6 +113,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml index 29dcfc8ad3..eafb91229f 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_filters__dfp_0.xml @@ -58,7 +58,7 @@ docstring: - + @@ -71,13 +71,12 @@ docstring: + + + + + - - - - - - diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml index 474bca4b1e..c4855938b4 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_join_to_time_spine_with_metric_time__dfp_0.xml @@ -20,6 +20,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml index 9e9f625875..0fe9a4187b 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_nested_derived_metric_with_outer_offset__dfp_0.xml @@ -19,6 +19,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + @@ -44,7 +49,7 @@ test_filename: test_dataflow_plan_builder.py - + @@ -62,6 +67,11 @@ test_filename: test_dataflow_plan_builder.py + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml index 85ac6913de..24643e555e 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml @@ -112,7 +112,7 @@ docstring: - + @@ -170,6 +170,11 @@ docstring: + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml index 3c8eabb9d8..9888e180e5 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml @@ -114,7 +114,7 @@ docstring: - + @@ -175,6 +175,11 @@ docstring: + + + + + @@ -246,7 +251,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/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 cb500cc780..c870939a85 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -539,12 +571,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 fd4d509af1..3b28e6b430 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 a8ff00ed4f..6cd456a008 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,50 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__month AS metric_time__month + , subq_2.ds__day + , subq_2.ds__week + , 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__martian_day + 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 +131,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 9bad19fa75..752fc1ea35 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' + -- Change Column Aliases + -- 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 527d9d0a4a..932bdb189a 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 d04af26bad..9ba7a69cbb 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATETIME_TRUNC(subq_21.ds, month) = sma_28009_cte.metric_time__day + DATETIME_TRUNC(time_spine_src_28006.ds, month) = sma_28009_cte.metric_time__day GROUP BY metric_time__day - ) subq_25 + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY metric_time__day -) subq_26 +) subq_28 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 6b8f5a9d66..71022a29e5 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,16 +578,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 f8e4cbb5a0..eff245bd90 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) AS metric_time__week - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) AS metric_time__week + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__week'] @@ -33,26 +33,26 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds, isoweek) AS metric_time__week + DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) AS metric_time__week , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATETIME_TRUNC(subq_21.ds, month) = sma_28009_cte.metric_time__day - WHERE DATETIME_TRUNC(subq_21.ds, isoweek) = subq_21.ds + DATETIME_TRUNC(time_spine_src_28006.ds, month) = sma_28009_cte.metric_time__day + WHERE DATETIME_TRUNC(time_spine_src_28006.ds, isoweek) = time_spine_src_28006.ds GROUP BY metric_time__week - ) subq_25 + ) subq_27 ON - subq_18.metric_time__week = subq_25.metric_time__week + subq_19.metric_time__week = subq_27.metric_time__week GROUP BY metric_time__week -) subq_26 +) subq_28 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 d4a80aad46..9d47f829b2 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 e203b9e8fc..bbbb66e301 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_21.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day GROUP BY metric_time__day - ) subq_25 + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY metric_time__day -) subq_26 +) subq_28 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 8d30776e8a..6f74beb8aa 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__week + , subq_7.ds__month + , 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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 27b465ac38..0ebcc74ed3 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) AS metric_time__quarter - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) AS metric_time__quarter + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__quarter'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds, quarter) AS metric_time__quarter + DATETIME_TRUNC(time_spine_src_28006.ds, quarter) AS metric_time__quarter , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_21.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day GROUP BY metric_time__quarter - ) subq_25 + ) subq_27 ON - subq_18.metric_time__quarter = subq_25.metric_time__quarter + subq_19.metric_time__quarter = subq_27.metric_time__quarter GROUP BY metric_time__quarter -) subq_26 +) subq_28 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 ec3e167f19..0dd7b5f393 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,236 +362,268 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +716,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 7e03f029fa..7ab10e3f9a 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 @@ -18,43 +18,43 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) AS metric_time__day - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) AS metric_time__day + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATETIME_TRUNC(subq_20.ds, month) = sma_28009_cte.metric_time__day + DATETIME_TRUNC(time_spine_src_28006.ds, month) = sma_28009_cte.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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_27.ds AS DATETIME), INTERVAL 1 month) = sma_28009_cte.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 month) = sma_28009_cte.metric_time__day GROUP BY metric_time__day - ) subq_31 + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY metric_time__day -) subq_32 +) subq_36 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 1a2e246f67..6386f07c5a 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -331,238 +363,270 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , 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__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_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 +719,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 36675c8e2a..3b0d975dab 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 @@ -18,44 +18,44 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) AS metric_time__year - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) AS metric_time__year + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + DATETIME_TRUNC(time_spine_src_28006.ds, year) AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATETIME_TRUNC(subq_20.ds, month) = sma_28009_cte.metric_time__day - WHERE DATETIME_TRUNC(subq_20.ds, year) = subq_20.ds + DATETIME_TRUNC(time_spine_src_28006.ds, month) = sma_28009_cte.metric_time__day + WHERE DATETIME_TRUNC(time_spine_src_28006.ds, year) = time_spine_src_28006.ds 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_27.ds, year) AS metric_time__year + DATETIME_TRUNC(time_spine_src_28006.ds, year) AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_27.ds AS DATETIME), INTERVAL 1 month) = sma_28009_cte.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 month) = sma_28009_cte.metric_time__day GROUP BY metric_time__year - ) subq_31 + ) subq_35 ON - subq_24.metric_time__year = subq_31.metric_time__year + subq_27.metric_time__year = subq_35.metric_time__year GROUP BY metric_time__year -) subq_32 +) subq_36 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 f2749ad4ac..1f61be8a86 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_8.ds__day AS metric_time__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__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_8 + ) subq_9 + ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -749,17 +781,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 e5d33e92b3..1413f00213 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_21.bookings) AS bookings - , MAX(subq_29.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_22.bookings) AS bookings + , MAX(subq_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -35,11 +35,11 @@ FROM ( metric_time__day , bookings FROM sma_28009_cte sma_28009_cte - ) 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'] @@ -51,20 +51,20 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_24.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_24 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_24.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day - ) subq_25 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day + ) subq_27 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_29 + ) subq_31 ON - subq_21.metric_time__day = subq_29.metric_time__day + subq_22.metric_time__day = subq_31.metric_time__day GROUP BY metric_time__day -) subq_30 +) subq_32 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 06985ad46c..ff91d278f4 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -438,10 +470,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 b66ab403f2..400b3fa431 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 2d791b43a7..f0b88193cf 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,129 +362,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 +577,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 9d4710e217..da48a3c1ea 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 @@ -19,25 +19,25 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_17.ds AS DATETIME), INTERVAL 1 week) = sma_28009_cte.booking__ds__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 week) = sma_28009_cte.booking__ds__day GROUP BY booking__ds__day - ) subq_21 + ) subq_23 FULL OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'booking__ds__day'] @@ -49,9 +49,9 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY booking__ds__day - ) subq_25 + ) subq_27 ON - subq_21.booking__ds__day = subq_25.booking__ds__day + subq_23.booking__ds__day = subq_27.booking__ds__day GROUP BY booking__ds__day -) subq_26 +) subq_28 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 58fb1dddbd..dda2283a04 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -324,10 +356,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 fcc4c15019..63ebed0c41 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 4a81cecb71..52b10c46e1 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,87 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +164,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 +187,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -356,18 +420,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 14f557c69d..95f6f4f23e 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 1e108238eb..4ae3180a0d 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__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__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 + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -245,129 +277,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 +492,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 6ae0b8c2f2..cac36acca2 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 @@ -18,15 +18,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_24.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_29.booking_fees) AS booking_fees + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_26.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_31.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 @@ -43,11 +43,11 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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 @@ -64,10 +64,10 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) subq_28 - ) subq_29 + ) subq_30 + ) subq_31 ON - subq_24.metric_time__day = subq_29.metric_time__day + subq_26.metric_time__day = subq_31.metric_time__day GROUP BY metric_time__day -) subq_30 +) subq_32 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 04e0bb15f3..9ba2d1f904 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,71 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +148,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 +171,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -340,14 +404,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 14d59bc467..6af166cd3e 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 3c020e799b..7c1d42554a 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 4183500d03..0f735319da 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 bc4faccfda..4685f9d783 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 974fba1880..46d5423668 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 1393c92843..a784c088fa 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,13 +460,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 9b21410866..3aa8c518de 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 6adab29d6b..52142a1cb9 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -336,12 +368,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 039f084b2c..d40e57e9aa 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 c05bb94edb..5d2f34ec77 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 79f8f13c0b..04c2e5d83f 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATETIME_TRUNC(subq_21.ds, month) = sma_28009_cte.booking__ds__day + DATETIME_TRUNC(time_spine_src_28006.ds, month) = sma_28009_cte.booking__ds__day GROUP BY booking__ds__day - ) subq_25 + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY booking__ds__day -) subq_26 +) subq_28 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 e5b6bdae73..fb697bd2a0 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -434,232 +466,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 +784,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 fa404c6fa5..8dfcf0c403 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 @@ -22,9 +22,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) AS metric_time__month - , MAX(subq_24.booking_value) AS booking_value - , MAX(subq_29.bookers) AS bookers + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) AS metric_time__month + , MAX(subq_26.booking_value) AS booking_value + , MAX(subq_31.bookers) AS bookers FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__month'] @@ -36,19 +36,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 , sma_28009_cte.booking_value AS booking_value - FROM ***************************.mf_time_spine subq_19 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_19.ds AS DATETIME), INTERVAL 1 week) = sma_28009_cte.metric_time__day - ) subq_20 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 week) = sma_28009_cte.metric_time__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'] @@ -65,13 +65,13 @@ FROM ( , booking_value , bookers FROM sma_28009_cte sma_28009_cte - ) subq_25 + ) subq_27 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_29 + ) subq_31 ON - subq_24.metric_time__month = subq_29.metric_time__month + subq_26.metric_time__month = subq_31.metric_time__month GROUP BY metric_time__month -) subq_30 +) subq_32 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 5e4750080c..49e10bf041 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -344,137 +376,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 +599,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 54ec83dc78..b731bb23ed 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 @@ -25,31 +25,31 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) AS metric_time__month - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) AS metric_time__year - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) AS metric_time__month + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) AS metric_time__year + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_17.ds AS DATETIME), INTERVAL 1 week) = sma_28009_cte.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 1 week) = sma_28009_cte.metric_time__day GROUP BY metric_time__day , metric_time__month , metric_time__year - ) subq_21 + ) subq_23 FULL OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] @@ -65,17 +65,17 @@ FROM ( metric_time__day , metric_time__month , metric_time__year - ) subq_25 + ) subq_27 ON ( - subq_21.metric_time__day = subq_25.metric_time__day + subq_23.metric_time__day = subq_27.metric_time__day ) AND ( - subq_21.metric_time__month = subq_25.metric_time__month + subq_23.metric_time__month = subq_27.metric_time__month ) AND ( - subq_21.metric_time__year = subq_25.metric_time__year + subq_23.metric_time__year = subq_27.metric_time__year ) GROUP BY metric_time__day , metric_time__month , metric_time__year -) subq_26 +) subq_28 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 d5a8ac8ec6..bbcc82dd47 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 4339eb86cc..6e2ebe8a48 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_21.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.booking__ds__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.booking__ds__day GROUP BY booking__ds__day - ) subq_25 + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY booking__ds__day -) subq_26 +) subq_28 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 0e9e30db37..ce8acd3447 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -425,12 +457,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 3bc29dc98f..423c4e1150 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 850c8a2464..b2d1cd36da 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -539,12 +571,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 8324d90b8b..4637576848 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 3dabd090e3..633620fbbd 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,50 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__month AS metric_time__month + , subq_2.ds__day + , subq_2.ds__week + , 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__martian_day + 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 +131,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 8dca633791..3c56987018 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' + -- Change Column Aliases + -- 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 134685c6ee..62cb64cb4f 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 de26580491..e4fa30e706 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 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 f09d32e7ed..f720d69796 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,16 +578,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 082815e98e..2e6fe8e65a 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) AS metric_time__week - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) AS metric_time__week + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__week'] @@ -33,26 +33,26 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__week + DATE_TRUNC('week', time_spine_src_28006.ds) AS metric_time__week , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('week', subq_21.ds) = subq_21.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = time_spine_src_28006.ds GROUP BY - DATE_TRUNC('week', subq_21.ds) - ) subq_25 + DATE_TRUNC('week', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__week = subq_25.metric_time__week + subq_19.metric_time__week = subq_27.metric_time__week GROUP BY - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) -) subq_26 + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) +) subq_28 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 16136ee1f8..40d1ffbeab 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 a68dcbb343..3bc8c7be7c 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 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 5bf84c68da..3a194c4c98 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__week + , subq_7.ds__month + , 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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 fb67b277fa..d4f50ad76a 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) AS metric_time__quarter - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) AS metric_time__quarter + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__quarter'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__quarter + DATE_TRUNC('quarter', time_spine_src_28006.ds) AS metric_time__quarter , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('quarter', subq_21.ds) - ) subq_25 + DATE_TRUNC('quarter', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__quarter = subq_25.metric_time__quarter + subq_19.metric_time__quarter = subq_27.metric_time__quarter GROUP BY - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) -) subq_26 + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) +) subq_28 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 5d7d7aa3ea..d2ca6e6602 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,236 +362,268 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +716,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 f35a4062e9..3c0b65baf5 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 @@ -18,43 +18,43 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) AS metric_time__day - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) AS metric_time__day + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, subq_27.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 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 011efcbf1e..7b6af2867f 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -331,238 +363,270 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , 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__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_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 +719,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 26940a100d..cb23b153ba 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 @@ -18,44 +18,44 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) AS metric_time__year - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) AS metric_time__year + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds 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_27.ds) AS metric_time__year + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, subq_27.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('year', subq_27.ds) - ) subq_31 + DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_35 ON - subq_24.metric_time__year = subq_31.metric_time__year + subq_27.metric_time__year = subq_35.metric_time__year GROUP BY - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) -) subq_32 + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) +) subq_36 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 10dc33073b..8657d58874 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_8.ds__day AS metric_time__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__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_8 + ) subq_9 + ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -749,17 +781,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 b4173eaa00..829bffa770 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_21.bookings) AS bookings - , MAX(subq_29.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_22.bookings) AS bookings + , MAX(subq_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -35,11 +35,11 @@ FROM ( metric_time__day , bookings FROM sma_28009_cte sma_28009_cte - ) 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'] @@ -51,20 +51,20 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_24.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_24 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_24.ds) = sma_28009_cte.metric_time__day - ) subq_25 + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_27 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_29 + ) subq_31 ON - subq_21.metric_time__day = subq_29.metric_time__day + subq_22.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) +) subq_32 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 636ea606b5..d4096225ae 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -438,10 +470,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 46f8a04db2..ee2e66dceb 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 88b69a224f..f51cbe6b47 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,129 +362,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 +577,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 454431f304..18ee936e10 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 @@ -19,25 +19,25 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(week, -1, subq_17.ds) = sma_28009_cte.booking__ds__day + DATEADD(week, -1, time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_17.ds - ) subq_21 + time_spine_src_28006.ds + ) subq_23 FULL OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'booking__ds__day'] @@ -49,9 +49,9 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY booking__ds__day - ) subq_25 + ) subq_27 ON - subq_21.booking__ds__day = subq_25.booking__ds__day + subq_23.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 f9d8141ddf..67e939c1e7 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -324,10 +356,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 ef9112432e..a466307d41 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 8d0f382179..128444fb48 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,87 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +164,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 +187,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -356,18 +420,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 6e2e83b479..89bcc32f7b 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 e8867090be..2d75a3cc8e 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__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__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 + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -245,129 +277,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 +492,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 858a0ec70c..60fce52c03 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 @@ -18,15 +18,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_24.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_29.booking_fees) AS booking_fees + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_26.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_31.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 @@ -43,11 +43,11 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) 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 @@ -64,10 +64,10 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) subq_28 - ) subq_29 + ) subq_30 + ) subq_31 ON - subq_24.metric_time__day = subq_29.metric_time__day + subq_26.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) +) subq_32 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 2a162caea8..3e48bc15a5 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,71 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +148,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 +171,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -340,14 +404,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 afed1816e7..9aec36d400 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 2b0efba5c2..9017891e14 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 8b3aac867a..837d11c0c1 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 4492ea2f39..b271d5f6d3 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 ec6b4352f0..7f46354fce 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 47a841cb29..a724cfc021 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,13 +460,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 a45feb0355..8951bbe9e9 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 976e8404a5..45777e8389 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -336,12 +368,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 5b6603fdff..34497b505f 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 62cf1b2253..24ae48d259 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 1682e2cc59..bec04eaa93 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.booking__ds__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 decfdb0bec..1cd9069be2 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -434,232 +466,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 +784,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 2a62e2106e..92b05eecc2 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 @@ -22,9 +22,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) AS metric_time__month - , MAX(subq_24.booking_value) AS booking_value - , MAX(subq_29.bookers) AS bookers + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) AS metric_time__month + , MAX(subq_26.booking_value) AS booking_value + , MAX(subq_31.bookers) AS bookers FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__month'] @@ -36,19 +36,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 , sma_28009_cte.booking_value AS booking_value - FROM ***************************.mf_time_spine subq_19 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(week, -1, subq_19.ds) = sma_28009_cte.metric_time__day - ) subq_20 + DATEADD(week, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__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'] @@ -65,13 +65,13 @@ FROM ( , booking_value , bookers FROM sma_28009_cte sma_28009_cte - ) subq_25 + ) subq_27 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_29 + ) subq_31 ON - subq_24.metric_time__month = subq_29.metric_time__month + subq_26.metric_time__month = subq_31.metric_time__month GROUP BY - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) -) subq_30 + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) +) subq_32 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 151fbd171c..6134a9a518 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -344,137 +376,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 +599,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 d71f78cece..3851699161 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 @@ -25,31 +25,31 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) AS metric_time__month - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) AS metric_time__year - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) AS metric_time__month + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) AS metric_time__year + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(week, -1, subq_17.ds) = sma_28009_cte.metric_time__day + DATEADD(week, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day 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 From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] @@ -65,17 +65,17 @@ FROM ( metric_time__day , metric_time__month , metric_time__year - ) subq_25 + ) subq_27 ON ( - subq_21.metric_time__day = subq_25.metric_time__day + subq_23.metric_time__day = subq_27.metric_time__day ) AND ( - subq_21.metric_time__month = subq_25.metric_time__month + subq_23.metric_time__month = subq_27.metric_time__month ) AND ( - subq_21.metric_time__year = subq_25.metric_time__year + subq_23.metric_time__year = subq_27.metric_time__year ) GROUP BY - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) -) subq_26 + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) +) subq_28 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 737cfa0f14..e6275211b1 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 0b964bf59b..c0b4d9a537 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.booking__ds__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 9440ae12f9..c3ac2ca2d4 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -425,12 +457,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 92a8d09760..93a5ebbb6b 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/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index c7ebdd463f..9fb1b5357e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day + subq_12.metric_time__day , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.bookers AS every_2_days_bookers_2_days_ago + subq_11.metric_time__day + , subq_11.bookers AS every_2_days_bookers_2_days_ago FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , COUNT(DISTINCT subq_9.bookers) AS bookers + subq_10.metric_time__day + , COUNT(DISTINCT subq_10.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.bookers + subq_9.metric_time__day + , subq_9.bookers FROM ( -- Constrain Time Range to [2019-12-19T00:00:00, 2020-01-02T00:00:00] SELECT - subq_7.metric_time__day - , subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.ds_partitioned__day - , subq_7.ds_partitioned__week - , subq_7.ds_partitioned__month - , subq_7.ds_partitioned__quarter - , subq_7.ds_partitioned__year - , subq_7.ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy - , subq_7.paid_at__day - , subq_7.paid_at__week - , subq_7.paid_at__month - , subq_7.paid_at__quarter - , subq_7.paid_at__year - , subq_7.paid_at__extract_year - , subq_7.paid_at__extract_quarter - , subq_7.paid_at__extract_month - , subq_7.paid_at__extract_day - , subq_7.paid_at__extract_dow - , subq_7.paid_at__extract_doy - , subq_7.booking__ds__day - , subq_7.booking__ds__week - , subq_7.booking__ds__month - , subq_7.booking__ds__quarter - , subq_7.booking__ds__year - , subq_7.booking__ds__extract_year - , subq_7.booking__ds__extract_quarter - , subq_7.booking__ds__extract_month - , subq_7.booking__ds__extract_day - , subq_7.booking__ds__extract_dow - , subq_7.booking__ds__extract_doy - , subq_7.booking__ds_partitioned__day - , subq_7.booking__ds_partitioned__week - , subq_7.booking__ds_partitioned__month - , subq_7.booking__ds_partitioned__quarter - , subq_7.booking__ds_partitioned__year - , subq_7.booking__ds_partitioned__extract_year - , subq_7.booking__ds_partitioned__extract_quarter - , subq_7.booking__ds_partitioned__extract_month - , subq_7.booking__ds_partitioned__extract_day - , subq_7.booking__ds_partitioned__extract_dow - , subq_7.booking__ds_partitioned__extract_doy - , subq_7.booking__paid_at__day - , subq_7.booking__paid_at__week - , subq_7.booking__paid_at__month - , subq_7.booking__paid_at__quarter - , subq_7.booking__paid_at__year - , subq_7.booking__paid_at__extract_year - , subq_7.booking__paid_at__extract_quarter - , subq_7.booking__paid_at__extract_month - , subq_7.booking__paid_at__extract_day - , subq_7.booking__paid_at__extract_dow - , subq_7.booking__paid_at__extract_doy - , subq_7.metric_time__week - , subq_7.metric_time__month - , subq_7.metric_time__quarter - , subq_7.metric_time__year - , subq_7.metric_time__extract_year - , subq_7.metric_time__extract_quarter - , subq_7.metric_time__extract_month - , subq_7.metric_time__extract_day - , subq_7.metric_time__extract_dow - , subq_7.metric_time__extract_doy - , subq_7.listing - , subq_7.guest - , subq_7.host - , subq_7.booking__listing - , subq_7.booking__guest - , subq_7.booking__host - , subq_7.is_instant - , subq_7.booking__is_instant - , subq_7.bookings - , subq_7.instant_bookings - , subq_7.booking_value - , subq_7.max_booking_value - , subq_7.min_booking_value - , subq_7.bookers - , subq_7.average_booking_value - , subq_7.referred_bookings - , subq_7.median_booking_value - , subq_7.booking_value_p99 - , subq_7.discrete_booking_value_p99 - , subq_7.approximate_continuous_booking_value_p99 - , subq_7.approximate_discrete_booking_value_p99 + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.ds_partitioned__day + , subq_8.ds_partitioned__week + , subq_8.ds_partitioned__month + , subq_8.ds_partitioned__quarter + , subq_8.ds_partitioned__year + , subq_8.ds_partitioned__extract_year + , subq_8.ds_partitioned__extract_quarter + , subq_8.ds_partitioned__extract_month + , subq_8.ds_partitioned__extract_day + , subq_8.ds_partitioned__extract_dow + , subq_8.ds_partitioned__extract_doy + , subq_8.paid_at__day + , subq_8.paid_at__week + , subq_8.paid_at__month + , subq_8.paid_at__quarter + , subq_8.paid_at__year + , subq_8.paid_at__extract_year + , subq_8.paid_at__extract_quarter + , subq_8.paid_at__extract_month + , subq_8.paid_at__extract_day + , subq_8.paid_at__extract_dow + , subq_8.paid_at__extract_doy + , subq_8.booking__ds__day + , subq_8.booking__ds__week + , subq_8.booking__ds__month + , subq_8.booking__ds__quarter + , subq_8.booking__ds__year + , subq_8.booking__ds__extract_year + , subq_8.booking__ds__extract_quarter + , subq_8.booking__ds__extract_month + , subq_8.booking__ds__extract_day + , subq_8.booking__ds__extract_dow + , subq_8.booking__ds__extract_doy + , subq_8.booking__ds_partitioned__day + , subq_8.booking__ds_partitioned__week + , subq_8.booking__ds_partitioned__month + , subq_8.booking__ds_partitioned__quarter + , subq_8.booking__ds_partitioned__year + , subq_8.booking__ds_partitioned__extract_year + , subq_8.booking__ds_partitioned__extract_quarter + , subq_8.booking__ds_partitioned__extract_month + , subq_8.booking__ds_partitioned__extract_day + , subq_8.booking__ds_partitioned__extract_dow + , subq_8.booking__ds_partitioned__extract_doy + , subq_8.booking__paid_at__day + , subq_8.booking__paid_at__week + , subq_8.booking__paid_at__month + , subq_8.booking__paid_at__quarter + , subq_8.booking__paid_at__year + , subq_8.booking__paid_at__extract_year + , subq_8.booking__paid_at__extract_quarter + , subq_8.booking__paid_at__extract_month + , subq_8.booking__paid_at__extract_day + , subq_8.booking__paid_at__extract_dow + , subq_8.booking__paid_at__extract_doy + , subq_8.metric_time__week + , subq_8.metric_time__month + , subq_8.metric_time__quarter + , subq_8.metric_time__year + , subq_8.metric_time__extract_year + , subq_8.metric_time__extract_quarter + , subq_8.metric_time__extract_month + , subq_8.metric_time__extract_day + , subq_8.metric_time__extract_dow + , subq_8.metric_time__extract_doy + , subq_8.metric_time__day + , subq_8.listing + , subq_8.guest + , subq_8.host + , subq_8.booking__listing + , subq_8.booking__guest + , subq_8.booking__host + , subq_8.is_instant + , subq_8.booking__is_instant + , subq_8.bookings + , subq_8.instant_bookings + , subq_8.booking_value + , subq_8.max_booking_value + , subq_8.min_booking_value + , subq_8.bookers + , subq_8.average_booking_value + , subq_8.referred_bookings + , subq_8.median_booking_value + , subq_8.booking_value_p99 + , subq_8.discrete_booking_value_p99 + , subq_8.approximate_continuous_booking_value_p99 + , subq_8.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -201,7 +201,7 @@ FROM ( , subq_4.metric_time__extract_day AS metric_time__extract_day , subq_4.metric_time__extract_dow AS metric_time__extract_dow , subq_4.metric_time__extract_doy AS metric_time__extract_doy - , subq_5.metric_time__day AS metric_time__day + , subq_7.metric_time__day AS metric_time__day , subq_4.listing AS listing , subq_4.guest AS guest , subq_4.host AS host @@ -224,11 +224,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -539,12 +571,12 @@ FROM ( ) ) subq_4 ON - subq_5.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day - ) subq_7 - WHERE subq_7.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' - ) subq_8 - ) subq_9 + subq_7.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day + ) subq_8 + WHERE subq_8.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' + ) subq_9 + ) subq_10 GROUP BY - subq_9.metric_time__day - ) subq_10 -) subq_11 + subq_10.metric_time__day + ) subq_11 +) subq_12 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql index c9708287a0..90bd2622f7 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql @@ -13,27 +13,27 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_18.ds AS metric_time__day - , COUNT(DISTINCT subq_16.bookers) AS every_2_days_bookers_2_days_ago - FROM ***************************.mf_time_spine subq_18 + time_spine_src_28006.ds AS metric_time__day + , COUNT(DISTINCT subq_17.bookers) AS every_2_days_bookers_2_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Join Self Over Time Range SELECT - subq_15.ds AS metric_time__day + subq_16.ds AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine subq_16 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_16.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_16.ds - INTERVAL 2 day ) - ) subq_16 + ) subq_17 ON - subq_18.ds - INTERVAL 2 day = subq_16.metric_time__day - WHERE subq_18.ds BETWEEN '2019-12-19' AND '2020-01-02' + time_spine_src_28006.ds - INTERVAL 2 day = subq_17.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_18.ds -) subq_23 + time_spine_src_28006.ds +) subq_25 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index fda110dcfa..38fb759489 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__month + subq_8.metric_time__month , bookings_last_month AS bookings_last_month FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__month - , subq_6.bookings_monthly AS bookings_last_month + subq_7.metric_time__month + , subq_7.bookings_monthly AS bookings_last_month FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__month - , SUM(subq_5.bookings_monthly) AS bookings_monthly + subq_6.metric_time__month + , SUM(subq_6.bookings_monthly) AS bookings_monthly FROM ( -- Pass Only Elements: ['bookings_monthly', 'metric_time__month'] SELECT - subq_4.metric_time__month - , subq_4.bookings_monthly + subq_5.metric_time__month + , subq_5.bookings_monthly FROM ( -- Join to Time Spine Dataset SELECT @@ -41,18 +41,50 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__month AS metric_time__month + , subq_2.ds__day + , subq_2.ds__week + , 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__martian_day + 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 +131,10 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__month - INTERVAL 1 month = subq_1.metric_time__month - ) subq_4 - ) subq_5 + subq_4.metric_time__month - INTERVAL 1 month = subq_1.metric_time__month + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__month - ) subq_6 -) subq_7 + subq_6.metric_time__month + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql index 4c78ac742c..c4e603d75e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql @@ -12,20 +12,22 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_10.metric_time__month AS metric_time__month + subq_13.metric_time__month AS metric_time__month , SUM(monthly_bookings_source_src_16000.bookings_monthly) AS bookings_last_month FROM ( -- Read From Time Spine 'mf_time_spine' + -- Change Column Aliases + -- Pass Only Elements: ['metric_time__month', 'metric_time__month'] SELECT DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_11 + FROM ***************************.mf_time_spine time_spine_src_16006 GROUP BY DATE_TRUNC('month', ds) - ) subq_10 + ) subq_13 INNER JOIN ***************************.fct_bookings_extended_monthly monthly_bookings_source_src_16000 ON - subq_10.metric_time__month - INTERVAL 1 month = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) + subq_13.metric_time__month - INTERVAL 1 month = DATE_TRUNC('month', monthly_bookings_source_src_16000.ds) GROUP BY - subq_10.metric_time__month -) subq_15 + subq_13.metric_time__month +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql index 245d56f88d..74b6d0a8aa 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_14.metric_time__day , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) AS metric_time__day + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) AS metric_time__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + , MAX(subq_13.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.bookings AS bookings_at_start_of_month + subq_12.metric_time__day + , subq_12.bookings AS bookings_at_start_of_month FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__day - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day + , subq_9.metric_time__day AS metric_time__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,15 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + DATE_TRUNC('month', subq_9.metric_time__day) = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__day - ) subq_11 - ) subq_12 + subq_11.metric_time__day + ) subq_12 + ) subq_13 ON - subq_4.metric_time__day = subq_12.metric_time__day + subq_4.metric_time__day = subq_13.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) -) subq_13 + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql index 936376f133..06ee1ddb8c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0_optimized.sql @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index bf9ad8dd43..675a437c72 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__week + subq_14.metric_time__week , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__week, subq_12.metric_time__week) AS metric_time__week + COALESCE(subq_4.metric_time__week, subq_13.metric_time__week) AS metric_time__week , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + , MAX(subq_13.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__week - , subq_11.bookings AS bookings_at_start_of_month + subq_12.metric_time__week + , subq_12.bookings AS bookings_at_start_of_month FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__week - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__week + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__week'] SELECT - subq_9.metric_time__week - , subq_9.bookings + subq_10.metric_time__week + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -320,8 +320,8 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__week AS metric_time__week + , subq_9.metric_time__day AS metric_time__day + , subq_9.metric_time__week AS metric_time__week , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,12 +344,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,16 +578,16 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day - WHERE subq_7.metric_time__week = subq_7.metric_time__day - ) subq_9 - ) subq_10 + DATE_TRUNC('month', subq_9.metric_time__day) = subq_6.metric_time__day + WHERE subq_9.metric_time__week = subq_9.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__week - ) subq_11 - ) subq_12 + subq_11.metric_time__week + ) subq_12 + ) subq_13 ON - subq_4.metric_time__week = subq_12.metric_time__week + subq_4.metric_time__week = subq_13.metric_time__week GROUP BY - COALESCE(subq_4.metric_time__week, subq_12.metric_time__week) -) subq_13 + COALESCE(subq_4.metric_time__week, subq_13.metric_time__week) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql index 20a1d3552e..27737461df 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) AS metric_time__week - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) AS metric_time__week + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__week'] @@ -33,26 +33,26 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__week + DATE_TRUNC('week', time_spine_src_28006.ds) AS metric_time__week , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('week', subq_21.ds) = subq_21.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = time_spine_src_28006.ds GROUP BY - DATE_TRUNC('week', subq_21.ds) - ) subq_25 + DATE_TRUNC('week', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__week = subq_25.metric_time__week + subq_19.metric_time__week = subq_27.metric_time__week GROUP BY - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) -) subq_26 + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) +) subq_28 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql index 3ec3c55d3d..23b51230bd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_14.metric_time__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) AS metric_time__day + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) AS metric_time__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.metric_time__day + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__day - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day + , subq_9.metric_time__day AS metric_time__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__day - ) subq_11 - ) subq_12 + subq_11.metric_time__day + ) subq_12 + ) subq_13 ON - subq_4.metric_time__day = subq_12.metric_time__day + subq_4.metric_time__day = subq_13.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) -) subq_13 + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql index 5fbf13a377..948f8402e1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0_optimized.sql @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_21.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 792cbdb254..4ede9e08d2 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__quarter + subq_14.metric_time__quarter , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__quarter, subq_12.metric_time__quarter) AS metric_time__quarter + COALESCE(subq_4.metric_time__quarter, subq_13.metric_time__quarter) AS metric_time__quarter , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__quarter - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.metric_time__quarter + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__quarter - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__quarter + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__quarter'] SELECT - subq_9.metric_time__quarter - , subq_9.bookings + subq_10.metric_time__quarter + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -320,8 +320,8 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__quarter AS metric_time__quarter + , subq_9.metric_time__day AS metric_time__day + , subq_9.metric_time__quarter AS metric_time__quarter , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,12 +344,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__week + , subq_7.ds__month + , 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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__quarter - ) subq_11 - ) subq_12 + subq_11.metric_time__quarter + ) subq_12 + ) subq_13 ON - subq_4.metric_time__quarter = subq_12.metric_time__quarter + subq_4.metric_time__quarter = subq_13.metric_time__quarter GROUP BY - COALESCE(subq_4.metric_time__quarter, subq_12.metric_time__quarter) -) subq_13 + COALESCE(subq_4.metric_time__quarter, subq_13.metric_time__quarter) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql index 7ffaaf7aac..ca94895765 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) AS metric_time__quarter - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) AS metric_time__quarter + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__quarter'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__quarter + DATE_TRUNC('quarter', time_spine_src_28006.ds) AS metric_time__quarter , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_21.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('quarter', subq_21.ds) - ) subq_25 + DATE_TRUNC('quarter', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__quarter = subq_25.metric_time__quarter + subq_19.metric_time__quarter = subq_27.metric_time__quarter GROUP BY - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) -) subq_26 + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) +) subq_28 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 50ff9446a0..067132e105 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -4,29 +4,29 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_16.metric_time__day + subq_18.metric_time__day , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) AS metric_time__day - , MAX(subq_7.month_start_bookings) AS month_start_bookings - , MAX(subq_15.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) AS metric_time__day + , MAX(subq_8.month_start_bookings) AS month_start_bookings + , MAX(subq_17.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings AS month_start_bookings + subq_7.metric_time__day + , subq_7.bookings AS month_start_bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -106,7 +106,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -129,11 +129,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,236 +362,268 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +716,18 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 + ) subq_9 + ) subq_10 ON - subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - INTERVAL 1 month = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY - subq_13.metric_time__day - ) subq_14 - ) subq_15 + subq_15.metric_time__day + ) subq_16 + ) subq_17 ON - subq_7.metric_time__day = subq_15.metric_time__day + subq_8.metric_time__day = subq_17.metric_time__day GROUP BY - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) -) subq_16 + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) +) subq_18 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql index e443c940f1..55af5dcf29 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql @@ -18,43 +18,43 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) AS metric_time__day - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) AS metric_time__day + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_27.ds - INTERVAL 1 month = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - INTERVAL 1 month = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index afc7ce6516..1d5827eea4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -4,29 +4,29 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_16.metric_time__year + subq_18.metric_time__year , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__year, subq_15.metric_time__year) AS metric_time__year - , MAX(subq_7.month_start_bookings) AS month_start_bookings - , MAX(subq_15.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_8.metric_time__year, subq_17.metric_time__year) AS metric_time__year + , MAX(subq_8.month_start_bookings) AS month_start_bookings + , MAX(subq_17.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__year - , subq_6.bookings AS month_start_bookings + subq_7.metric_time__year + , subq_7.bookings AS month_start_bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__year - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__year + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__year'] SELECT - subq_4.metric_time__year - , subq_4.bookings + subq_5.metric_time__year + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -105,8 +105,8 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__year AS metric_time__year + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__year AS metric_time__year , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -129,12 +129,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -331,238 +363,270 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , 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__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_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 +719,18 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 + ) subq_9 + ) subq_10 ON - subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - INTERVAL 1 month = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY - subq_13.metric_time__year - ) subq_14 - ) subq_15 + subq_15.metric_time__year + ) subq_16 + ) subq_17 ON - subq_7.metric_time__year = subq_15.metric_time__year + subq_8.metric_time__year = subq_17.metric_time__year GROUP BY - COALESCE(subq_7.metric_time__year, subq_15.metric_time__year) -) subq_16 + COALESCE(subq_8.metric_time__year, subq_17.metric_time__year) +) subq_18 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql index 42e0278057..1bc7c8040f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql @@ -18,44 +18,44 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) AS metric_time__year - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) AS metric_time__year + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds 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_27.ds) AS metric_time__year + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_27.ds - INTERVAL 1 month = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - INTERVAL 1 month = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('year', subq_27.ds) - ) subq_31 + DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_35 ON - subq_24.metric_time__year = subq_31.metric_time__year + subq_27.metric_time__year = subq_35.metric_time__year GROUP BY - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) -) subq_32 + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) +) subq_36 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index e88a2f9f3e..68adc9df28 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day + subq_16.metric_time__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_5.metric_time__day, subq_14.metric_time__day) AS metric_time__day + COALESCE(subq_5.metric_time__day, subq_15.metric_time__day) AS metric_time__day , MAX(subq_5.bookings) AS bookings - , MAX(subq_14.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_15.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -333,119 +333,119 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day - , subq_13.bookings AS bookings_2_weeks_ago + subq_14.metric_time__day + , subq_14.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_12.metric_time__day - , SUM(subq_12.bookings) AS bookings + subq_13.metric_time__day + , SUM(subq_13.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_11.metric_time__day - , subq_11.bookings + subq_12.metric_time__day + , subq_12.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_10.metric_time__day - , subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.ds_partitioned__day - , subq_10.ds_partitioned__week - , subq_10.ds_partitioned__month - , subq_10.ds_partitioned__quarter - , subq_10.ds_partitioned__year - , subq_10.ds_partitioned__extract_year - , subq_10.ds_partitioned__extract_quarter - , subq_10.ds_partitioned__extract_month - , subq_10.ds_partitioned__extract_day - , subq_10.ds_partitioned__extract_dow - , subq_10.ds_partitioned__extract_doy - , subq_10.paid_at__day - , subq_10.paid_at__week - , subq_10.paid_at__month - , subq_10.paid_at__quarter - , subq_10.paid_at__year - , subq_10.paid_at__extract_year - , subq_10.paid_at__extract_quarter - , subq_10.paid_at__extract_month - , subq_10.paid_at__extract_day - , subq_10.paid_at__extract_dow - , subq_10.paid_at__extract_doy - , subq_10.booking__ds__day - , subq_10.booking__ds__week - , subq_10.booking__ds__month - , subq_10.booking__ds__quarter - , subq_10.booking__ds__year - , subq_10.booking__ds__extract_year - , subq_10.booking__ds__extract_quarter - , subq_10.booking__ds__extract_month - , subq_10.booking__ds__extract_day - , subq_10.booking__ds__extract_dow - , subq_10.booking__ds__extract_doy - , subq_10.booking__ds_partitioned__day - , subq_10.booking__ds_partitioned__week - , subq_10.booking__ds_partitioned__month - , subq_10.booking__ds_partitioned__quarter - , subq_10.booking__ds_partitioned__year - , subq_10.booking__ds_partitioned__extract_year - , subq_10.booking__ds_partitioned__extract_quarter - , subq_10.booking__ds_partitioned__extract_month - , subq_10.booking__ds_partitioned__extract_day - , subq_10.booking__ds_partitioned__extract_dow - , subq_10.booking__ds_partitioned__extract_doy - , subq_10.booking__paid_at__day - , subq_10.booking__paid_at__week - , subq_10.booking__paid_at__month - , subq_10.booking__paid_at__quarter - , subq_10.booking__paid_at__year - , subq_10.booking__paid_at__extract_year - , subq_10.booking__paid_at__extract_quarter - , subq_10.booking__paid_at__extract_month - , subq_10.booking__paid_at__extract_day - , subq_10.booking__paid_at__extract_dow - , subq_10.booking__paid_at__extract_doy - , subq_10.metric_time__week - , subq_10.metric_time__month - , subq_10.metric_time__quarter - , subq_10.metric_time__year - , subq_10.metric_time__extract_year - , subq_10.metric_time__extract_quarter - , subq_10.metric_time__extract_month - , subq_10.metric_time__extract_day - , subq_10.metric_time__extract_dow - , subq_10.metric_time__extract_doy - , subq_10.listing - , subq_10.guest - , subq_10.host - , subq_10.booking__listing - , subq_10.booking__guest - , subq_10.booking__host - , subq_10.is_instant - , subq_10.booking__is_instant - , subq_10.bookings - , subq_10.instant_bookings - , subq_10.booking_value - , subq_10.max_booking_value - , subq_10.min_booking_value - , subq_10.bookers - , subq_10.average_booking_value - , subq_10.referred_bookings - , subq_10.median_booking_value - , subq_10.booking_value_p99 - , subq_10.discrete_booking_value_p99 - , subq_10.approximate_continuous_booking_value_p99 - , subq_10.approximate_discrete_booking_value_p99 + subq_11.ds__day + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , subq_11.ds__year + , subq_11.ds__extract_year + , subq_11.ds__extract_quarter + , subq_11.ds__extract_month + , subq_11.ds__extract_day + , subq_11.ds__extract_dow + , subq_11.ds__extract_doy + , subq_11.ds_partitioned__day + , subq_11.ds_partitioned__week + , subq_11.ds_partitioned__month + , subq_11.ds_partitioned__quarter + , subq_11.ds_partitioned__year + , subq_11.ds_partitioned__extract_year + , subq_11.ds_partitioned__extract_quarter + , subq_11.ds_partitioned__extract_month + , subq_11.ds_partitioned__extract_day + , subq_11.ds_partitioned__extract_dow + , subq_11.ds_partitioned__extract_doy + , subq_11.paid_at__day + , subq_11.paid_at__week + , subq_11.paid_at__month + , subq_11.paid_at__quarter + , subq_11.paid_at__year + , subq_11.paid_at__extract_year + , subq_11.paid_at__extract_quarter + , subq_11.paid_at__extract_month + , subq_11.paid_at__extract_day + , subq_11.paid_at__extract_dow + , subq_11.paid_at__extract_doy + , subq_11.booking__ds__day + , subq_11.booking__ds__week + , subq_11.booking__ds__month + , subq_11.booking__ds__quarter + , subq_11.booking__ds__year + , subq_11.booking__ds__extract_year + , subq_11.booking__ds__extract_quarter + , subq_11.booking__ds__extract_month + , subq_11.booking__ds__extract_day + , subq_11.booking__ds__extract_dow + , subq_11.booking__ds__extract_doy + , subq_11.booking__ds_partitioned__day + , subq_11.booking__ds_partitioned__week + , subq_11.booking__ds_partitioned__month + , subq_11.booking__ds_partitioned__quarter + , subq_11.booking__ds_partitioned__year + , subq_11.booking__ds_partitioned__extract_year + , subq_11.booking__ds_partitioned__extract_quarter + , subq_11.booking__ds_partitioned__extract_month + , subq_11.booking__ds_partitioned__extract_day + , subq_11.booking__ds_partitioned__extract_dow + , subq_11.booking__ds_partitioned__extract_doy + , subq_11.booking__paid_at__day + , subq_11.booking__paid_at__week + , subq_11.booking__paid_at__month + , subq_11.booking__paid_at__quarter + , subq_11.booking__paid_at__year + , subq_11.booking__paid_at__extract_year + , subq_11.booking__paid_at__extract_quarter + , subq_11.booking__paid_at__extract_month + , subq_11.booking__paid_at__extract_day + , subq_11.booking__paid_at__extract_dow + , subq_11.booking__paid_at__extract_doy + , subq_11.metric_time__week + , subq_11.metric_time__month + , subq_11.metric_time__quarter + , subq_11.metric_time__year + , subq_11.metric_time__extract_year + , subq_11.metric_time__extract_quarter + , subq_11.metric_time__extract_month + , subq_11.metric_time__extract_day + , subq_11.metric_time__extract_dow + , subq_11.metric_time__extract_doy + , subq_11.metric_time__day + , subq_11.listing + , subq_11.guest + , subq_11.host + , subq_11.booking__listing + , subq_11.booking__guest + , subq_11.booking__host + , subq_11.is_instant + , subq_11.booking__is_instant + , subq_11.bookings + , subq_11.instant_bookings + , subq_11.booking_value + , subq_11.max_booking_value + , subq_11.min_booking_value + , subq_11.bookers + , subq_11.average_booking_value + , subq_11.referred_bookings + , subq_11.median_booking_value + , subq_11.booking_value_p99 + , subq_11.discrete_booking_value_p99 + , subq_11.approximate_continuous_booking_value_p99 + , subq_11.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -525,7 +525,7 @@ FROM ( , subq_7.metric_time__extract_day AS metric_time__extract_day , subq_7.metric_time__extract_dow AS metric_time__extract_dow , subq_7.metric_time__extract_doy AS metric_time__extract_doy - , subq_8.metric_time__day AS metric_time__day + , subq_10.metric_time__day AS metric_time__day , subq_7.listing AS listing , subq_7.guest AS guest , subq_7.host AS host @@ -548,11 +548,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_8.ds__day AS metric_time__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__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_8 + ) subq_9 + ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -749,17 +781,17 @@ FROM ( ) subq_6 ) subq_7 ON - subq_8.metric_time__day - INTERVAL 14 day = subq_7.metric_time__day - ) subq_10 + subq_10.metric_time__day - INTERVAL 14 day = subq_7.metric_time__day + ) subq_11 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' - ) subq_11 - ) subq_12 + ) subq_12 + ) subq_13 GROUP BY - subq_12.metric_time__day - ) subq_13 - ) subq_14 + subq_13.metric_time__day + ) subq_14 + ) subq_15 ON - subq_5.metric_time__day = subq_14.metric_time__day + subq_5.metric_time__day = subq_15.metric_time__day GROUP BY - COALESCE(subq_5.metric_time__day, subq_14.metric_time__day) -) subq_15 + COALESCE(subq_5.metric_time__day, subq_15.metric_time__day) +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql index d96abac35a..74406cf6d8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_21.bookings) AS bookings - , MAX(subq_29.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_22.bookings) AS bookings + , MAX(subq_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -35,11 +35,11 @@ FROM ( metric_time__day , bookings FROM sma_28009_cte sma_28009_cte - ) 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'] @@ -51,20 +51,20 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_24.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_24 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_24.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day - ) subq_25 + time_spine_src_28006.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day + ) subq_27 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_29 + ) subq_31 ON - subq_21.metric_time__day = subq_29.metric_time__day + subq_22.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) +) subq_32 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql index 7a0c96d981..0b939c32fd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day + subq_11.metric_time__day , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day - , subq_9.bookers AS every_2_days_bookers_2_days_ago + subq_10.metric_time__day + , subq_10.bookers AS every_2_days_bookers_2_days_ago FROM ( -- Aggregate Measures SELECT - subq_8.metric_time__day - , COUNT(DISTINCT subq_8.bookers) AS bookers + subq_9.metric_time__day + , COUNT(DISTINCT subq_9.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.bookers + subq_8.metric_time__day + , subq_8.bookers FROM ( -- Join to Time Spine Dataset SELECT @@ -100,7 +100,7 @@ FROM ( , subq_4.metric_time__extract_day AS metric_time__extract_day , subq_4.metric_time__extract_dow AS metric_time__extract_dow , subq_4.metric_time__extract_doy AS metric_time__extract_doy - , subq_5.metric_time__day AS metric_time__day + , subq_7.metric_time__day AS metric_time__day , subq_4.listing AS listing , subq_4.guest AS guest , subq_4.host AS host @@ -123,11 +123,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -438,10 +470,10 @@ FROM ( ) ) subq_4 ON - subq_5.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day - ) subq_7 - ) subq_8 + subq_7.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day + ) subq_8 + ) subq_9 GROUP BY - subq_8.metric_time__day - ) subq_9 -) subq_10 + subq_9.metric_time__day + ) subq_10 +) subq_11 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql index 47db02e9dd..adf2d6a797 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0_optimized.sql @@ -12,26 +12,26 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS metric_time__day - , COUNT(DISTINCT subq_15.bookers) AS every_2_days_bookers_2_days_ago - FROM ***************************.mf_time_spine subq_17 + time_spine_src_28006.ds AS metric_time__day + , COUNT(DISTINCT subq_16.bookers) AS every_2_days_bookers_2_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Join Self Over Time Range SELECT - subq_14.ds AS metric_time__day + subq_15.ds AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_15.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_15.ds - INTERVAL 2 day ) - ) subq_15 + ) subq_16 ON - subq_17.ds - INTERVAL 2 day = subq_15.metric_time__day + time_spine_src_28006.ds - INTERVAL 2 day = subq_16.metric_time__day GROUP BY - subq_17.ds -) subq_21 + time_spine_src_28006.ds +) subq_23 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 5e5ede6026..a1be9bcd30 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -4,29 +4,29 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_14.booking__ds__day , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.booking__ds__day, subq_12.booking__ds__day) AS booking__ds__day - , MAX(subq_7.booking_value) AS booking_value - , MAX(subq_12.bookers) AS bookers + COALESCE(subq_8.booking__ds__day, subq_13.booking__ds__day) AS booking__ds__day + , MAX(subq_8.booking_value) AS booking_value + , MAX(subq_13.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_6.booking__ds__day - , subq_6.booking_value + subq_7.booking__ds__day + , subq_7.booking_value FROM ( -- Aggregate Measures SELECT - subq_5.booking__ds__day - , SUM(subq_5.booking_value) AS booking_value + subq_6.booking__ds__day + , SUM(subq_6.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__ds__day'] SELECT - subq_4.booking__ds__day - , subq_4.booking_value + subq_5.booking__ds__day + , subq_5.booking_value FROM ( -- Join to Time Spine Dataset SELECT @@ -106,7 +106,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.booking__ds__day AS booking__ds__day + , subq_4.booking__ds__day AS booking__ds__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -129,11 +129,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,129 +362,129 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.booking__ds__day - INTERVAL 1 week = subq_1.booking__ds__day - ) subq_4 - ) subq_5 + subq_4.booking__ds__day - INTERVAL 1 week = subq_1.booking__ds__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.booking__ds__day - ) subq_6 - ) subq_7 + subq_6.booking__ds__day + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.booking__ds__day - , subq_11.bookers + subq_12.booking__ds__day + , subq_12.bookers FROM ( -- Aggregate Measures SELECT - subq_10.booking__ds__day - , COUNT(DISTINCT subq_10.bookers) AS bookers + subq_11.booking__ds__day + , COUNT(DISTINCT subq_11.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'booking__ds__day'] SELECT - subq_9.booking__ds__day - , subq_9.bookers + subq_10.booking__ds__day + , subq_10.bookers FROM ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -545,15 +577,15 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 - ) subq_10 + ) subq_9 + ) subq_10 + ) subq_11 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_11.booking__ds__day + ) subq_12 + ) subq_13 ON - subq_7.booking__ds__day = subq_12.booking__ds__day + subq_8.booking__ds__day = subq_13.booking__ds__day GROUP BY - COALESCE(subq_7.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_8.booking__ds__day, subq_13.booking__ds__day) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql index 6ff0744b02..bb7b97f611 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0_optimized.sql @@ -19,25 +19,25 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_17.ds - INTERVAL 1 week = sma_28009_cte.booking__ds__day + time_spine_src_28006.ds - INTERVAL 1 week = sma_28009_cte.booking__ds__day GROUP BY - subq_17.ds - ) subq_21 + time_spine_src_28006.ds + ) subq_23 FULL OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'booking__ds__day'] @@ -49,9 +49,9 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY booking__ds__day - ) subq_25 + ) subq_27 ON - subq_21.booking__ds__day = subq_25.booking__ds__day + subq_23.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) +) subq_28 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql index 6cc7df6c9f..ae7f93f3a0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_8.metric_time__day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings AS bookings_5_days_ago + subq_7.metric_time__day + , subq_7.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -100,7 +100,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -123,11 +123,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -324,10 +356,10 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 -) subq_7 + subq_6.metric_time__day + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql index 4a3f73badc..9de842c717 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql @@ -12,9 +12,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ds AS metric_time__day - , SUM(subq_9.bookings) AS bookings_5_days_ago - FROM ***************************.mf_time_spine subq_11 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_10.bookings) AS bookings_5_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -22,9 +22,9 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 ON - subq_11.ds - INTERVAL 5 day = subq_9.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_10.metric_time__day GROUP BY - subq_11.ds -) subq_15 + time_spine_src_28006.ds +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 9c0bdbd42b..113c469f62 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -4,55 +4,87 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_15.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Pass Only Elements: ['metric_time__day', 'bookings_offset_once'] SELECT - subq_12.metric_time__day - , subq_12.bookings_offset_once + subq_14.metric_time__day + , subq_14.bookings_offset_once FROM ( -- Constrain Output with WHERE SELECT - subq_11.metric_time__day - , subq_11.booking__is_instant - , subq_11.bookings_offset_once + subq_13.metric_time__day + , subq_13.booking__is_instant + , subq_13.bookings_offset_once FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.booking__is_instant AS booking__is_instant - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.booking__is_instant AS booking__is_instant + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +164,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 +187,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -356,18 +420,18 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - , subq_5.booking__is_instant - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + , subq_6.booking__is_instant + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day - ) subq_11 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day + ) subq_13 WHERE booking__is_instant - ) subq_12 -) subq_13 + ) subq_14 +) subq_15 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql index d62752cb4f..42b7243264 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql @@ -15,10 +15,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_24.ds AS metric_time__day - , subq_22.booking__is_instant AS booking__is_instant - , subq_22.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_24 + time_spine_src_28006.ds AS metric_time__day + , subq_25.booking__is_instant AS booking__is_instant + , subq_25.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -31,10 +31,10 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.ds AS metric_time__day - , subq_15.booking__is_instant AS booking__is_instant - , SUM(subq_15.bookings) AS bookings - FROM ***************************.mf_time_spine subq_17 + time_spine_src_28006.ds AS metric_time__day + , subq_17.booking__is_instant AS booking__is_instant + , SUM(subq_17.bookings) AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -43,16 +43,16 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + ) subq_17 ON - subq_17.ds - INTERVAL 5 day = subq_15.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_17.metric_time__day GROUP BY - subq_17.ds - , subq_15.booking__is_instant - ) subq_21 - ) subq_22 + time_spine_src_28006.ds + , subq_17.booking__is_instant + ) subq_24 + ) subq_25 ON - subq_24.ds - INTERVAL 2 day = subq_22.metric_time__day - ) subq_25 + time_spine_src_28006.ds - INTERVAL 2 day = subq_25.metric_time__day + ) subq_29 WHERE booking__is_instant -) subq_27 +) subq_31 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql index 968a86830c..a28f87d3c3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql @@ -4,25 +4,57 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day + subq_16.metric_time__day , booking_fees - booking_fees_start_of_month AS booking_fees_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_8.metric_time__day, subq_14.metric_time__day) AS metric_time__day - , MAX(subq_8.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_14.booking_fees) AS booking_fees + COALESCE(subq_9.metric_time__day, subq_15.metric_time__day) AS metric_time__day + , MAX(subq_9.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_15.booking_fees) AS booking_fees FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_5.booking_fees_start_of_month AS booking_fees_start_of_month FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_7.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__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__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 + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -245,129 +277,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 +492,16 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_10 + ) subq_11 + ) subq_12 GROUP BY - subq_11.metric_time__day - ) subq_12 - ) subq_13 - ) subq_14 + subq_12.metric_time__day + ) subq_13 + ) subq_14 + ) subq_15 ON - subq_8.metric_time__day = subq_14.metric_time__day + subq_9.metric_time__day = subq_15.metric_time__day GROUP BY - COALESCE(subq_8.metric_time__day, subq_14.metric_time__day) -) subq_15 + COALESCE(subq_9.metric_time__day, subq_15.metric_time__day) +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql index 7518d98883..c577329a06 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql @@ -18,15 +18,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_24.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_29.booking_fees) AS booking_fees + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_26.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_31.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 @@ -43,11 +43,11 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) 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 @@ -64,10 +64,10 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) subq_28 - ) subq_29 + ) subq_30 + ) subq_31 ON - subq_24.metric_time__day = subq_29.metric_time__day + subq_26.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) +) subq_32 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql index b3f4befad2..38289e3485 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql @@ -4,39 +4,71 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day + subq_13.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +148,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 +171,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -340,14 +404,14 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day -) subq_11 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql index ec796be86d..fe15c86bd4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_22.ds AS metric_time__day - , subq_20.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_22 + time_spine_src_28006.ds AS metric_time__day + , subq_23.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -23,9 +23,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_15.ds AS metric_time__day - , SUM(subq_13.bookings) AS bookings - FROM ***************************.mf_time_spine subq_15 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_15.bookings) AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -33,13 +33,13 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_15 ON - subq_15.ds - INTERVAL 5 day = subq_13.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_15.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + time_spine_src_28006.ds + ) subq_22 + ) subq_23 ON - subq_22.ds - INTERVAL 2 day = subq_20.metric_time__day -) subq_23 + time_spine_src_28006.ds - INTERVAL 2 day = subq_23.metric_time__day +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql index a719769718..039c8b9ec6 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql @@ -4,44 +4,76 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day + subq_14.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - subq_11.metric_time__day - , subq_11.bookings_offset_once + subq_13.metric_time__day + , subq_13.bookings_offset_once FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,16 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day - ) subq_11 - WHERE subq_11.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' -) subq_12 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day + ) subq_13 + WHERE subq_13.metric_time__day BETWEEN '2020-01-12' AND '2020-01-13' +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql index 457a8a18d9..6a16e0902d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0_optimized.sql @@ -10,9 +10,9 @@ FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-12T00:00:00, 2020-01-13T00:00:00] SELECT - subq_23.ds AS metric_time__day - , subq_21.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_23 + time_spine_src_28006.ds AS metric_time__day + , subq_24.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -24,9 +24,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_16.ds AS metric_time__day - , SUM(subq_14.bookings) AS bookings - FROM ***************************.mf_time_spine subq_16 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_16.bookings) AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -34,14 +34,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_16 ON - subq_16.ds - INTERVAL 5 day = subq_14.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - subq_23.ds - INTERVAL 2 day = subq_21.metric_time__day - WHERE subq_23.ds BETWEEN '2020-01-12' AND '2020-01-13' -) subq_25 + time_spine_src_28006.ds - INTERVAL 2 day = subq_24.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2020-01-12' AND '2020-01-13' +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql index 1645b05276..e792f137ec 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql @@ -4,44 +4,76 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day + subq_14.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( -- Constrain Output with WHERE SELECT - subq_11.metric_time__day - , subq_11.bookings_offset_once + subq_13.metric_time__day + , subq_13.bookings_offset_once FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day - , subq_8.bookings_offset_once AS bookings_offset_once + subq_12.metric_time__day AS metric_time__day + , subq_9.bookings_offset_once AS bookings_offset_once FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_11.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,16 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_6.metric_time__day + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day - ) subq_11 + subq_12.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day + ) subq_13 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' -) subq_12 +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql index 5d979eb0ce..c25d4f0b95 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql @@ -14,9 +14,9 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_23.ds AS metric_time__day - , subq_21.bookings_offset_once AS bookings_offset_once - FROM ***************************.mf_time_spine subq_23 + time_spine_src_28006.ds AS metric_time__day + , subq_24.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -28,9 +28,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_16.ds AS metric_time__day - , SUM(subq_14.bookings) AS bookings - FROM ***************************.mf_time_spine subq_16 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_16.bookings) AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -38,15 +38,15 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_16 ON - subq_16.ds - INTERVAL 5 day = subq_14.metric_time__day + time_spine_src_28006.ds - INTERVAL 5 day = subq_16.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + time_spine_src_28006.ds + ) subq_23 + ) subq_24 ON - subq_23.ds - INTERVAL 2 day = subq_21.metric_time__day - ) subq_24 + time_spine_src_28006.ds - INTERVAL 2 day = subq_24.metric_time__day + ) subq_28 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' -) subq_25 +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 470dd41cc3..b0b6ac3fd0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,124 +6,124 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__month + subq_9.metric_time__month , bookings_start_of_month AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__month - , subq_7.bookings AS bookings_start_of_month + subq_8.metric_time__month + , subq_8.bookings AS bookings_start_of_month FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__month - , SUM(subq_6.bookings) AS bookings + subq_7.metric_time__month + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__month'] SELECT - subq_5.metric_time__month - , subq_5.bookings + subq_6.metric_time__month + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.ds__day - , subq_4.ds__week - , subq_4.ds__month - , subq_4.ds__quarter - , subq_4.ds__year - , subq_4.ds__extract_year - , subq_4.ds__extract_quarter - , subq_4.ds__extract_month - , subq_4.ds__extract_day - , subq_4.ds__extract_dow - , subq_4.ds__extract_doy - , subq_4.ds_partitioned__day - , subq_4.ds_partitioned__week - , subq_4.ds_partitioned__month - , subq_4.ds_partitioned__quarter - , subq_4.ds_partitioned__year - , subq_4.ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy - , subq_4.paid_at__day - , subq_4.paid_at__week - , subq_4.paid_at__month - , subq_4.paid_at__quarter - , subq_4.paid_at__year - , subq_4.paid_at__extract_year - , subq_4.paid_at__extract_quarter - , subq_4.paid_at__extract_month - , subq_4.paid_at__extract_day - , subq_4.paid_at__extract_dow - , subq_4.paid_at__extract_doy - , subq_4.booking__ds__day - , subq_4.booking__ds__week - , subq_4.booking__ds__month - , subq_4.booking__ds__quarter - , subq_4.booking__ds__year - , subq_4.booking__ds__extract_year - , subq_4.booking__ds__extract_quarter - , subq_4.booking__ds__extract_month - , subq_4.booking__ds__extract_day - , subq_4.booking__ds__extract_dow - , subq_4.booking__ds__extract_doy - , subq_4.booking__ds_partitioned__day - , subq_4.booking__ds_partitioned__week - , subq_4.booking__ds_partitioned__month - , subq_4.booking__ds_partitioned__quarter - , subq_4.booking__ds_partitioned__year - , subq_4.booking__ds_partitioned__extract_year - , subq_4.booking__ds_partitioned__extract_quarter - , subq_4.booking__ds_partitioned__extract_month - , subq_4.booking__ds_partitioned__extract_day - , subq_4.booking__ds_partitioned__extract_dow - , subq_4.booking__ds_partitioned__extract_doy - , subq_4.booking__paid_at__day - , subq_4.booking__paid_at__week - , subq_4.booking__paid_at__month - , subq_4.booking__paid_at__quarter - , subq_4.booking__paid_at__year - , subq_4.booking__paid_at__extract_year - , subq_4.booking__paid_at__extract_quarter - , subq_4.booking__paid_at__extract_month - , subq_4.booking__paid_at__extract_day - , subq_4.booking__paid_at__extract_dow - , subq_4.booking__paid_at__extract_doy - , subq_4.metric_time__week - , subq_4.metric_time__quarter - , subq_4.metric_time__year - , subq_4.metric_time__extract_year - , subq_4.metric_time__extract_quarter - , subq_4.metric_time__extract_month - , subq_4.metric_time__extract_day - , subq_4.metric_time__extract_dow - , subq_4.metric_time__extract_doy - , subq_4.listing - , subq_4.guest - , subq_4.host - , subq_4.booking__listing - , subq_4.booking__guest - , subq_4.booking__host - , subq_4.is_instant - , subq_4.booking__is_instant - , subq_4.bookings - , subq_4.instant_bookings - , subq_4.booking_value - , subq_4.max_booking_value - , subq_4.min_booking_value - , subq_4.bookers - , subq_4.average_booking_value - , subq_4.referred_bookings - , subq_4.median_booking_value - , subq_4.booking_value_p99 - , subq_4.discrete_booking_value_p99 - , subq_4.approximate_continuous_booking_value_p99 - , subq_4.approximate_discrete_booking_value_p99 + subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.ds_partitioned__day + , subq_5.ds_partitioned__week + , subq_5.ds_partitioned__month + , subq_5.ds_partitioned__quarter + , subq_5.ds_partitioned__year + , subq_5.ds_partitioned__extract_year + , subq_5.ds_partitioned__extract_quarter + , subq_5.ds_partitioned__extract_month + , subq_5.ds_partitioned__extract_day + , subq_5.ds_partitioned__extract_dow + , subq_5.ds_partitioned__extract_doy + , subq_5.paid_at__day + , subq_5.paid_at__week + , subq_5.paid_at__month + , subq_5.paid_at__quarter + , subq_5.paid_at__year + , subq_5.paid_at__extract_year + , subq_5.paid_at__extract_quarter + , subq_5.paid_at__extract_month + , subq_5.paid_at__extract_day + , subq_5.paid_at__extract_dow + , subq_5.paid_at__extract_doy + , subq_5.booking__ds__day + , subq_5.booking__ds__week + , subq_5.booking__ds__month + , subq_5.booking__ds__quarter + , subq_5.booking__ds__year + , subq_5.booking__ds__extract_year + , subq_5.booking__ds__extract_quarter + , subq_5.booking__ds__extract_month + , subq_5.booking__ds__extract_day + , subq_5.booking__ds__extract_dow + , subq_5.booking__ds__extract_doy + , subq_5.booking__ds_partitioned__day + , subq_5.booking__ds_partitioned__week + , subq_5.booking__ds_partitioned__month + , subq_5.booking__ds_partitioned__quarter + , subq_5.booking__ds_partitioned__year + , subq_5.booking__ds_partitioned__extract_year + , subq_5.booking__ds_partitioned__extract_quarter + , subq_5.booking__ds_partitioned__extract_month + , subq_5.booking__ds_partitioned__extract_day + , subq_5.booking__ds_partitioned__extract_dow + , subq_5.booking__ds_partitioned__extract_doy + , subq_5.booking__paid_at__day + , subq_5.booking__paid_at__week + , subq_5.booking__paid_at__month + , subq_5.booking__paid_at__quarter + , subq_5.booking__paid_at__year + , subq_5.booking__paid_at__extract_year + , subq_5.booking__paid_at__extract_quarter + , subq_5.booking__paid_at__extract_month + , subq_5.booking__paid_at__extract_day + , subq_5.booking__paid_at__extract_dow + , subq_5.booking__paid_at__extract_doy + , subq_5.metric_time__week + , subq_5.metric_time__quarter + , subq_5.metric_time__year + , subq_5.metric_time__extract_year + , subq_5.metric_time__extract_quarter + , subq_5.metric_time__extract_month + , subq_5.metric_time__extract_day + , subq_5.metric_time__extract_dow + , subq_5.metric_time__extract_doy + , subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.listing + , subq_5.guest + , subq_5.host + , subq_5.booking__listing + , subq_5.booking__guest + , subq_5.booking__host + , subq_5.is_instant + , subq_5.booking__is_instant + , subq_5.bookings + , subq_5.instant_bookings + , subq_5.booking_value + , subq_5.max_booking_value + , subq_5.min_booking_value + , subq_5.bookers + , subq_5.average_booking_value + , subq_5.referred_bookings + , subq_5.median_booking_value + , subq_5.booking_value_p99 + , subq_5.discrete_booking_value_p99 + , subq_5.approximate_continuous_booking_value_p99 + , subq_5.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -202,8 +202,8 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -226,12 +226,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,13 +460,13 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - WHERE subq_2.metric_time__month = subq_2.metric_time__day - ) subq_4 + DATE_TRUNC('month', subq_4.metric_time__day) = subq_1.metric_time__day + WHERE subq_4.metric_time__month = subq_4.metric_time__day + ) subq_5 WHERE metric_time__day = '2020-01-01' - ) subq_5 - ) subq_6 + ) subq_6 + ) subq_7 GROUP BY - subq_6.metric_time__month - ) subq_7 -) subq_8 + subq_7.metric_time__month + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 29518080d5..bf2aed0b01 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -19,10 +19,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_12.ds AS metric_time__day - , DATE_TRUNC('month', subq_12.ds) AS metric_time__month - , subq_10.bookings AS bookings - FROM ***************************.mf_time_spine subq_12 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -30,12 +30,12 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - DATE_TRUNC('month', subq_12.ds) = subq_10.metric_time__day - WHERE DATE_TRUNC('month', subq_12.ds) = subq_12.ds - ) subq_13 + DATE_TRUNC('month', time_spine_src_28006.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', time_spine_src_28006.ds) = time_spine_src_28006.ds + ) subq_15 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month -) subq_17 +) subq_19 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql index e89f0ed249..6fd81d09c8 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -6,31 +6,31 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.metric_time__month - , subq_7.metric_time__year + subq_8.metric_time__day + , subq_8.metric_time__month + , subq_8.metric_time__year , bookings_start_of_month AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__month - , subq_6.metric_time__year - , subq_6.bookings AS bookings_start_of_month + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , subq_7.bookings AS bookings_start_of_month FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - , SUM(subq_5.bookings) AS bookings + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , SUM(subq_6.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.metric_time__year - , subq_4.bookings + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , subq_5.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -108,9 +108,9 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month - , subq_2.metric_time__year AS metric_time__year + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month + , subq_4.metric_time__year AS metric_time__year , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -133,13 +133,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -336,12 +368,12 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + DATE_TRUNC('month', subq_4.metric_time__day) = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - ) subq_6 -) subq_7 + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index d92697dcfc..95d682c27d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql @@ -16,11 +16,11 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ds AS metric_time__day - , DATE_TRUNC('month', subq_11.ds) AS metric_time__month - , DATE_TRUNC('year', subq_11.ds) AS metric_time__year - , SUM(subq_9.bookings) AS bookings_start_of_month - FROM ***************************.mf_time_spine subq_11 + time_spine_src_28006.ds AS metric_time__day + , DATE_TRUNC('month', time_spine_src_28006.ds) AS metric_time__month + , DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year + , SUM(subq_10.bookings) AS bookings_start_of_month + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -28,11 +28,11 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 ON - DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = subq_10.metric_time__day GROUP BY - subq_11.ds - , DATE_TRUNC('month', subq_11.ds) - , DATE_TRUNC('year', subq_11.ds) -) subq_15 + time_spine_src_28006.ds + , DATE_TRUNC('month', time_spine_src_28006.ds) + , DATE_TRUNC('year', time_spine_src_28006.ds) +) subq_17 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql index a9a36007ac..f1e8089cd5 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_14.booking__ds__day , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) AS booking__ds__day + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) AS booking__ds__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + , MAX(subq_13.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.booking__ds__day - , subq_11.bookings AS bookings_at_start_of_month + subq_12.booking__ds__day + , subq_12.bookings AS bookings_at_start_of_month FROM ( -- Aggregate Measures SELECT - subq_10.booking__ds__day - , SUM(subq_10.bookings) AS bookings + subq_11.booking__ds__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__ds__day'] SELECT - subq_9.booking__ds__day - , subq_9.bookings + subq_10.booking__ds__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.booking__ds__day AS booking__ds__day + , subq_9.booking__ds__day AS booking__ds__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,15 @@ FROM ( ) subq_5 ) subq_6 ON - DATE_TRUNC('month', subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + DATE_TRUNC('month', subq_9.booking__ds__day) = subq_6.booking__ds__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_11.booking__ds__day + ) subq_12 + ) subq_13 ON - subq_4.booking__ds__day = subq_12.booking__ds__day + subq_4.booking__ds__day = subq_13.booking__ds__day GROUP BY - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql index 0ced6d38ab..1807061266 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0_optimized.sql @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.booking__ds__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index 547e6fe97f..11695bd14c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -6,130 +6,130 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_15.metric_time__month + subq_16.metric_time__month , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_8.metric_time__month, subq_14.metric_time__month) AS metric_time__month - , MAX(subq_8.booking_value) AS booking_value - , MAX(subq_14.bookers) AS bookers + COALESCE(subq_9.metric_time__month, subq_15.metric_time__month) AS metric_time__month + , MAX(subq_9.booking_value) AS booking_value + , MAX(subq_15.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__month - , subq_7.booking_value + subq_8.metric_time__month + , subq_8.booking_value FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__month - , SUM(subq_6.booking_value) AS booking_value + subq_7.metric_time__month + , SUM(subq_7.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__month'] SELECT - subq_5.metric_time__month - , subq_5.booking_value + subq_6.metric_time__month + , subq_6.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.ds__day - , subq_4.ds__week - , subq_4.ds__month - , subq_4.ds__quarter - , subq_4.ds__year - , subq_4.ds__extract_year - , subq_4.ds__extract_quarter - , subq_4.ds__extract_month - , subq_4.ds__extract_day - , subq_4.ds__extract_dow - , subq_4.ds__extract_doy - , subq_4.ds_partitioned__day - , subq_4.ds_partitioned__week - , subq_4.ds_partitioned__month - , subq_4.ds_partitioned__quarter - , subq_4.ds_partitioned__year - , subq_4.ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy - , subq_4.paid_at__day - , subq_4.paid_at__week - , subq_4.paid_at__month - , subq_4.paid_at__quarter - , subq_4.paid_at__year - , subq_4.paid_at__extract_year - , subq_4.paid_at__extract_quarter - , subq_4.paid_at__extract_month - , subq_4.paid_at__extract_day - , subq_4.paid_at__extract_dow - , subq_4.paid_at__extract_doy - , subq_4.booking__ds__day - , subq_4.booking__ds__week - , subq_4.booking__ds__month - , subq_4.booking__ds__quarter - , subq_4.booking__ds__year - , subq_4.booking__ds__extract_year - , subq_4.booking__ds__extract_quarter - , subq_4.booking__ds__extract_month - , subq_4.booking__ds__extract_day - , subq_4.booking__ds__extract_dow - , subq_4.booking__ds__extract_doy - , subq_4.booking__ds_partitioned__day - , subq_4.booking__ds_partitioned__week - , subq_4.booking__ds_partitioned__month - , subq_4.booking__ds_partitioned__quarter - , subq_4.booking__ds_partitioned__year - , subq_4.booking__ds_partitioned__extract_year - , subq_4.booking__ds_partitioned__extract_quarter - , subq_4.booking__ds_partitioned__extract_month - , subq_4.booking__ds_partitioned__extract_day - , subq_4.booking__ds_partitioned__extract_dow - , subq_4.booking__ds_partitioned__extract_doy - , subq_4.booking__paid_at__day - , subq_4.booking__paid_at__week - , subq_4.booking__paid_at__month - , subq_4.booking__paid_at__quarter - , subq_4.booking__paid_at__year - , subq_4.booking__paid_at__extract_year - , subq_4.booking__paid_at__extract_quarter - , subq_4.booking__paid_at__extract_month - , subq_4.booking__paid_at__extract_day - , subq_4.booking__paid_at__extract_dow - , subq_4.booking__paid_at__extract_doy - , subq_4.metric_time__week - , subq_4.metric_time__quarter - , subq_4.metric_time__year - , subq_4.metric_time__extract_year - , subq_4.metric_time__extract_quarter - , subq_4.metric_time__extract_month - , subq_4.metric_time__extract_day - , subq_4.metric_time__extract_dow - , subq_4.metric_time__extract_doy - , subq_4.listing - , subq_4.guest - , subq_4.host - , subq_4.booking__listing - , subq_4.booking__guest - , subq_4.booking__host - , subq_4.is_instant - , subq_4.booking__is_instant - , subq_4.bookings - , subq_4.instant_bookings - , subq_4.booking_value - , subq_4.max_booking_value - , subq_4.min_booking_value - , subq_4.bookers - , subq_4.average_booking_value - , subq_4.referred_bookings - , subq_4.median_booking_value - , subq_4.booking_value_p99 - , subq_4.discrete_booking_value_p99 - , subq_4.approximate_continuous_booking_value_p99 - , subq_4.approximate_discrete_booking_value_p99 + subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.ds_partitioned__day + , subq_5.ds_partitioned__week + , subq_5.ds_partitioned__month + , subq_5.ds_partitioned__quarter + , subq_5.ds_partitioned__year + , subq_5.ds_partitioned__extract_year + , subq_5.ds_partitioned__extract_quarter + , subq_5.ds_partitioned__extract_month + , subq_5.ds_partitioned__extract_day + , subq_5.ds_partitioned__extract_dow + , subq_5.ds_partitioned__extract_doy + , subq_5.paid_at__day + , subq_5.paid_at__week + , subq_5.paid_at__month + , subq_5.paid_at__quarter + , subq_5.paid_at__year + , subq_5.paid_at__extract_year + , subq_5.paid_at__extract_quarter + , subq_5.paid_at__extract_month + , subq_5.paid_at__extract_day + , subq_5.paid_at__extract_dow + , subq_5.paid_at__extract_doy + , subq_5.booking__ds__day + , subq_5.booking__ds__week + , subq_5.booking__ds__month + , subq_5.booking__ds__quarter + , subq_5.booking__ds__year + , subq_5.booking__ds__extract_year + , subq_5.booking__ds__extract_quarter + , subq_5.booking__ds__extract_month + , subq_5.booking__ds__extract_day + , subq_5.booking__ds__extract_dow + , subq_5.booking__ds__extract_doy + , subq_5.booking__ds_partitioned__day + , subq_5.booking__ds_partitioned__week + , subq_5.booking__ds_partitioned__month + , subq_5.booking__ds_partitioned__quarter + , subq_5.booking__ds_partitioned__year + , subq_5.booking__ds_partitioned__extract_year + , subq_5.booking__ds_partitioned__extract_quarter + , subq_5.booking__ds_partitioned__extract_month + , subq_5.booking__ds_partitioned__extract_day + , subq_5.booking__ds_partitioned__extract_dow + , subq_5.booking__ds_partitioned__extract_doy + , subq_5.booking__paid_at__day + , subq_5.booking__paid_at__week + , subq_5.booking__paid_at__month + , subq_5.booking__paid_at__quarter + , subq_5.booking__paid_at__year + , subq_5.booking__paid_at__extract_year + , subq_5.booking__paid_at__extract_quarter + , subq_5.booking__paid_at__extract_month + , subq_5.booking__paid_at__extract_day + , subq_5.booking__paid_at__extract_dow + , subq_5.booking__paid_at__extract_doy + , subq_5.metric_time__week + , subq_5.metric_time__quarter + , subq_5.metric_time__year + , subq_5.metric_time__extract_year + , subq_5.metric_time__extract_quarter + , subq_5.metric_time__extract_month + , subq_5.metric_time__extract_day + , subq_5.metric_time__extract_dow + , subq_5.metric_time__extract_doy + , subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.listing + , subq_5.guest + , subq_5.host + , subq_5.booking__listing + , subq_5.booking__guest + , subq_5.booking__host + , subq_5.is_instant + , subq_5.booking__is_instant + , subq_5.bookings + , subq_5.instant_bookings + , subq_5.booking_value + , subq_5.max_booking_value + , subq_5.min_booking_value + , subq_5.bookers + , subq_5.average_booking_value + , subq_5.referred_bookings + , subq_5.median_booking_value + , subq_5.booking_value_p99 + , subq_5.discrete_booking_value_p99 + , subq_5.approximate_continuous_booking_value_p99 + , subq_5.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -208,8 +208,8 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -232,12 +232,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -434,232 +466,232 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day - ) subq_4 + subq_4.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day + ) subq_5 WHERE metric_time__day = '2020-01-01' - ) subq_5 - ) subq_6 + ) subq_6 + ) subq_7 GROUP BY - subq_6.metric_time__month - ) subq_7 - ) subq_8 + subq_7.metric_time__month + ) subq_8 + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_13.metric_time__month - , subq_13.bookers + subq_14.metric_time__month + , subq_14.bookers FROM ( -- Aggregate Measures SELECT - subq_12.metric_time__month - , COUNT(DISTINCT subq_12.bookers) AS bookers + subq_13.metric_time__month + , COUNT(DISTINCT subq_13.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__month'] SELECT - subq_11.metric_time__month - , subq_11.bookers + subq_12.metric_time__month + , subq_12.bookers FROM ( -- Constrain Output with WHERE SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.ds_partitioned__day - , subq_10.ds_partitioned__week - , subq_10.ds_partitioned__month - , subq_10.ds_partitioned__quarter - , subq_10.ds_partitioned__year - , subq_10.ds_partitioned__extract_year - , subq_10.ds_partitioned__extract_quarter - , subq_10.ds_partitioned__extract_month - , subq_10.ds_partitioned__extract_day - , subq_10.ds_partitioned__extract_dow - , subq_10.ds_partitioned__extract_doy - , subq_10.paid_at__day - , subq_10.paid_at__week - , subq_10.paid_at__month - , subq_10.paid_at__quarter - , subq_10.paid_at__year - , subq_10.paid_at__extract_year - , subq_10.paid_at__extract_quarter - , subq_10.paid_at__extract_month - , subq_10.paid_at__extract_day - , subq_10.paid_at__extract_dow - , subq_10.paid_at__extract_doy - , subq_10.booking__ds__day - , subq_10.booking__ds__week - , subq_10.booking__ds__month - , subq_10.booking__ds__quarter - , subq_10.booking__ds__year - , subq_10.booking__ds__extract_year - , subq_10.booking__ds__extract_quarter - , subq_10.booking__ds__extract_month - , subq_10.booking__ds__extract_day - , subq_10.booking__ds__extract_dow - , subq_10.booking__ds__extract_doy - , subq_10.booking__ds_partitioned__day - , subq_10.booking__ds_partitioned__week - , subq_10.booking__ds_partitioned__month - , subq_10.booking__ds_partitioned__quarter - , subq_10.booking__ds_partitioned__year - , subq_10.booking__ds_partitioned__extract_year - , subq_10.booking__ds_partitioned__extract_quarter - , subq_10.booking__ds_partitioned__extract_month - , subq_10.booking__ds_partitioned__extract_day - , subq_10.booking__ds_partitioned__extract_dow - , subq_10.booking__ds_partitioned__extract_doy - , subq_10.booking__paid_at__day - , subq_10.booking__paid_at__week - , subq_10.booking__paid_at__month - , subq_10.booking__paid_at__quarter - , subq_10.booking__paid_at__year - , subq_10.booking__paid_at__extract_year - , subq_10.booking__paid_at__extract_quarter - , subq_10.booking__paid_at__extract_month - , subq_10.booking__paid_at__extract_day - , subq_10.booking__paid_at__extract_dow - , subq_10.booking__paid_at__extract_doy - , subq_10.metric_time__day - , subq_10.metric_time__week - , subq_10.metric_time__month - , subq_10.metric_time__quarter - , subq_10.metric_time__year - , subq_10.metric_time__extract_year - , subq_10.metric_time__extract_quarter - , subq_10.metric_time__extract_month - , subq_10.metric_time__extract_day - , subq_10.metric_time__extract_dow - , subq_10.metric_time__extract_doy - , subq_10.listing - , subq_10.guest - , subq_10.host - , subq_10.booking__listing - , subq_10.booking__guest - , subq_10.booking__host - , subq_10.is_instant - , subq_10.booking__is_instant - , subq_10.bookings - , subq_10.instant_bookings - , subq_10.booking_value - , subq_10.max_booking_value - , subq_10.min_booking_value - , subq_10.bookers - , subq_10.average_booking_value - , subq_10.referred_bookings - , subq_10.median_booking_value - , subq_10.booking_value_p99 - , subq_10.discrete_booking_value_p99 - , subq_10.approximate_continuous_booking_value_p99 - , subq_10.approximate_discrete_booking_value_p99 + subq_11.ds__day + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , subq_11.ds__year + , subq_11.ds__extract_year + , subq_11.ds__extract_quarter + , subq_11.ds__extract_month + , subq_11.ds__extract_day + , subq_11.ds__extract_dow + , subq_11.ds__extract_doy + , subq_11.ds_partitioned__day + , subq_11.ds_partitioned__week + , subq_11.ds_partitioned__month + , subq_11.ds_partitioned__quarter + , subq_11.ds_partitioned__year + , subq_11.ds_partitioned__extract_year + , subq_11.ds_partitioned__extract_quarter + , subq_11.ds_partitioned__extract_month + , subq_11.ds_partitioned__extract_day + , subq_11.ds_partitioned__extract_dow + , subq_11.ds_partitioned__extract_doy + , subq_11.paid_at__day + , subq_11.paid_at__week + , subq_11.paid_at__month + , subq_11.paid_at__quarter + , subq_11.paid_at__year + , subq_11.paid_at__extract_year + , subq_11.paid_at__extract_quarter + , subq_11.paid_at__extract_month + , subq_11.paid_at__extract_day + , subq_11.paid_at__extract_dow + , subq_11.paid_at__extract_doy + , subq_11.booking__ds__day + , subq_11.booking__ds__week + , subq_11.booking__ds__month + , subq_11.booking__ds__quarter + , subq_11.booking__ds__year + , subq_11.booking__ds__extract_year + , subq_11.booking__ds__extract_quarter + , subq_11.booking__ds__extract_month + , subq_11.booking__ds__extract_day + , subq_11.booking__ds__extract_dow + , subq_11.booking__ds__extract_doy + , subq_11.booking__ds_partitioned__day + , subq_11.booking__ds_partitioned__week + , subq_11.booking__ds_partitioned__month + , subq_11.booking__ds_partitioned__quarter + , subq_11.booking__ds_partitioned__year + , subq_11.booking__ds_partitioned__extract_year + , subq_11.booking__ds_partitioned__extract_quarter + , subq_11.booking__ds_partitioned__extract_month + , subq_11.booking__ds_partitioned__extract_day + , subq_11.booking__ds_partitioned__extract_dow + , subq_11.booking__ds_partitioned__extract_doy + , subq_11.booking__paid_at__day + , subq_11.booking__paid_at__week + , subq_11.booking__paid_at__month + , subq_11.booking__paid_at__quarter + , subq_11.booking__paid_at__year + , subq_11.booking__paid_at__extract_year + , subq_11.booking__paid_at__extract_quarter + , subq_11.booking__paid_at__extract_month + , subq_11.booking__paid_at__extract_day + , subq_11.booking__paid_at__extract_dow + , subq_11.booking__paid_at__extract_doy + , subq_11.metric_time__day + , subq_11.metric_time__week + , subq_11.metric_time__month + , subq_11.metric_time__quarter + , subq_11.metric_time__year + , subq_11.metric_time__extract_year + , subq_11.metric_time__extract_quarter + , subq_11.metric_time__extract_month + , subq_11.metric_time__extract_day + , subq_11.metric_time__extract_dow + , subq_11.metric_time__extract_doy + , subq_11.listing + , subq_11.guest + , subq_11.host + , subq_11.booking__listing + , subq_11.booking__guest + , subq_11.booking__host + , subq_11.is_instant + , subq_11.booking__is_instant + , subq_11.bookings + , subq_11.instant_bookings + , subq_11.booking_value + , subq_11.max_booking_value + , subq_11.min_booking_value + , subq_11.bookers + , subq_11.average_booking_value + , subq_11.referred_bookings + , subq_11.median_booking_value + , subq_11.booking_value_p99 + , subq_11.discrete_booking_value_p99 + , subq_11.approximate_continuous_booking_value_p99 + , subq_11.approximate_discrete_booking_value_p99 FROM ( -- Metric Time Dimension 'ds' SELECT - subq_9.ds__day - , subq_9.ds__week - , subq_9.ds__month - , subq_9.ds__quarter - , subq_9.ds__year - , subq_9.ds__extract_year - , subq_9.ds__extract_quarter - , subq_9.ds__extract_month - , subq_9.ds__extract_day - , subq_9.ds__extract_dow - , subq_9.ds__extract_doy - , subq_9.ds_partitioned__day - , subq_9.ds_partitioned__week - , subq_9.ds_partitioned__month - , subq_9.ds_partitioned__quarter - , subq_9.ds_partitioned__year - , subq_9.ds_partitioned__extract_year - , subq_9.ds_partitioned__extract_quarter - , subq_9.ds_partitioned__extract_month - , subq_9.ds_partitioned__extract_day - , subq_9.ds_partitioned__extract_dow - , subq_9.ds_partitioned__extract_doy - , subq_9.paid_at__day - , subq_9.paid_at__week - , subq_9.paid_at__month - , subq_9.paid_at__quarter - , subq_9.paid_at__year - , subq_9.paid_at__extract_year - , subq_9.paid_at__extract_quarter - , subq_9.paid_at__extract_month - , subq_9.paid_at__extract_day - , subq_9.paid_at__extract_dow - , subq_9.paid_at__extract_doy - , subq_9.booking__ds__day - , subq_9.booking__ds__week - , subq_9.booking__ds__month - , subq_9.booking__ds__quarter - , subq_9.booking__ds__year - , subq_9.booking__ds__extract_year - , subq_9.booking__ds__extract_quarter - , subq_9.booking__ds__extract_month - , subq_9.booking__ds__extract_day - , subq_9.booking__ds__extract_dow - , subq_9.booking__ds__extract_doy - , subq_9.booking__ds_partitioned__day - , subq_9.booking__ds_partitioned__week - , subq_9.booking__ds_partitioned__month - , subq_9.booking__ds_partitioned__quarter - , subq_9.booking__ds_partitioned__year - , subq_9.booking__ds_partitioned__extract_year - , subq_9.booking__ds_partitioned__extract_quarter - , subq_9.booking__ds_partitioned__extract_month - , subq_9.booking__ds_partitioned__extract_day - , subq_9.booking__ds_partitioned__extract_dow - , subq_9.booking__ds_partitioned__extract_doy - , subq_9.booking__paid_at__day - , subq_9.booking__paid_at__week - , subq_9.booking__paid_at__month - , subq_9.booking__paid_at__quarter - , subq_9.booking__paid_at__year - , subq_9.booking__paid_at__extract_year - , subq_9.booking__paid_at__extract_quarter - , subq_9.booking__paid_at__extract_month - , subq_9.booking__paid_at__extract_day - , subq_9.booking__paid_at__extract_dow - , subq_9.booking__paid_at__extract_doy - , subq_9.ds__day AS metric_time__day - , subq_9.ds__week AS metric_time__week - , subq_9.ds__month AS metric_time__month - , subq_9.ds__quarter AS metric_time__quarter - , subq_9.ds__year AS metric_time__year - , subq_9.ds__extract_year AS metric_time__extract_year - , subq_9.ds__extract_quarter AS metric_time__extract_quarter - , subq_9.ds__extract_month AS metric_time__extract_month - , subq_9.ds__extract_day AS metric_time__extract_day - , subq_9.ds__extract_dow AS metric_time__extract_dow - , subq_9.ds__extract_doy AS metric_time__extract_doy - , subq_9.listing - , subq_9.guest - , subq_9.host - , subq_9.booking__listing - , subq_9.booking__guest - , subq_9.booking__host - , subq_9.is_instant - , subq_9.booking__is_instant - , subq_9.bookings - , subq_9.instant_bookings - , subq_9.booking_value - , subq_9.max_booking_value - , subq_9.min_booking_value - , subq_9.bookers - , subq_9.average_booking_value - , subq_9.referred_bookings - , subq_9.median_booking_value - , subq_9.booking_value_p99 - , subq_9.discrete_booking_value_p99 - , subq_9.approximate_continuous_booking_value_p99 - , subq_9.approximate_discrete_booking_value_p99 + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -752,17 +784,17 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 - ) subq_10 + ) subq_10 + ) subq_11 WHERE metric_time__day = '2020-01-01' - ) subq_11 - ) subq_12 + ) subq_12 + ) subq_13 GROUP BY - subq_12.metric_time__month - ) subq_13 - ) subq_14 + subq_13.metric_time__month + ) subq_14 + ) subq_15 ON - subq_8.metric_time__month = subq_14.metric_time__month + subq_9.metric_time__month = subq_15.metric_time__month GROUP BY - COALESCE(subq_8.metric_time__month, subq_14.metric_time__month) -) subq_15 + COALESCE(subq_9.metric_time__month, subq_15.metric_time__month) +) subq_16 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql index 898d2becc1..d3b66855aa 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -22,9 +22,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) AS metric_time__month - , MAX(subq_24.booking_value) AS booking_value - , MAX(subq_29.bookers) AS bookers + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) AS metric_time__month + , MAX(subq_26.booking_value) AS booking_value + , MAX(subq_31.bookers) AS bookers FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__month'] @@ -36,19 +36,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 , sma_28009_cte.booking_value AS booking_value - FROM ***************************.mf_time_spine subq_19 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_19.ds - INTERVAL 1 week = sma_28009_cte.metric_time__day - ) subq_20 + time_spine_src_28006.ds - INTERVAL 1 week = sma_28009_cte.metric_time__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'] @@ -65,13 +65,13 @@ FROM ( , booking_value , bookers FROM sma_28009_cte sma_28009_cte - ) subq_25 + ) subq_27 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_29 + ) subq_31 ON - subq_24.metric_time__month = subq_29.metric_time__month + subq_26.metric_time__month = subq_31.metric_time__month GROUP BY - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) -) subq_30 + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) +) subq_32 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql index 3b4a0a5883..7a8245bafb 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql @@ -6,39 +6,39 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day - , subq_13.metric_time__month - , subq_13.metric_time__year + subq_14.metric_time__day + , subq_14.metric_time__month + , subq_14.metric_time__year , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day - , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) AS metric_time__month - , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) AS metric_time__year - , MAX(subq_7.booking_value) AS booking_value - , MAX(subq_12.bookers) AS bookers + COALESCE(subq_8.metric_time__day, subq_13.metric_time__day) AS metric_time__day + , COALESCE(subq_8.metric_time__month, subq_13.metric_time__month) AS metric_time__month + , COALESCE(subq_8.metric_time__year, subq_13.metric_time__year) AS metric_time__year + , MAX(subq_8.booking_value) AS booking_value + , MAX(subq_13.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__month - , subq_6.metric_time__year - , subq_6.booking_value + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , subq_7.booking_value FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - , SUM(subq_5.booking_value) AS booking_value + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , SUM(subq_6.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.metric_time__year - , subq_4.booking_value + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , subq_5.booking_value FROM ( -- Join to Time Spine Dataset SELECT @@ -116,9 +116,9 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month - , subq_2.metric_time__year AS metric_time__year + , subq_4.metric_time__day AS metric_time__day + , subq_4.metric_time__month AS metric_time__month + , subq_4.metric_time__year AS metric_time__year , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -141,13 +141,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -344,137 +376,137 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day - ) subq_4 - ) subq_5 + subq_4.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - ) subq_6 - ) subq_7 + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + ) subq_7 + ) subq_8 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.metric_time__month - , subq_11.metric_time__year - , subq_11.bookers + subq_12.metric_time__day + , subq_12.metric_time__month + , subq_12.metric_time__year + , subq_12.bookers FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__day - , subq_10.metric_time__month - , subq_10.metric_time__year - , COUNT(DISTINCT subq_10.bookers) AS bookers + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + , COUNT(DISTINCT subq_11.bookers) AS bookers FROM ( -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] SELECT - subq_9.metric_time__day - , subq_9.metric_time__month - , subq_9.metric_time__year - , subq_9.bookers + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + , subq_10.bookers FROM ( -- Metric Time Dimension 'ds' SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.ds_partitioned__day - , subq_8.ds_partitioned__week - , subq_8.ds_partitioned__month - , subq_8.ds_partitioned__quarter - , subq_8.ds_partitioned__year - , subq_8.ds_partitioned__extract_year - , subq_8.ds_partitioned__extract_quarter - , subq_8.ds_partitioned__extract_month - , subq_8.ds_partitioned__extract_day - , subq_8.ds_partitioned__extract_dow - , subq_8.ds_partitioned__extract_doy - , subq_8.paid_at__day - , subq_8.paid_at__week - , subq_8.paid_at__month - , subq_8.paid_at__quarter - , subq_8.paid_at__year - , subq_8.paid_at__extract_year - , subq_8.paid_at__extract_quarter - , subq_8.paid_at__extract_month - , subq_8.paid_at__extract_day - , subq_8.paid_at__extract_dow - , subq_8.paid_at__extract_doy - , subq_8.booking__ds__day - , subq_8.booking__ds__week - , subq_8.booking__ds__month - , subq_8.booking__ds__quarter - , subq_8.booking__ds__year - , subq_8.booking__ds__extract_year - , subq_8.booking__ds__extract_quarter - , subq_8.booking__ds__extract_month - , subq_8.booking__ds__extract_day - , subq_8.booking__ds__extract_dow - , subq_8.booking__ds__extract_doy - , subq_8.booking__ds_partitioned__day - , subq_8.booking__ds_partitioned__week - , subq_8.booking__ds_partitioned__month - , subq_8.booking__ds_partitioned__quarter - , subq_8.booking__ds_partitioned__year - , subq_8.booking__ds_partitioned__extract_year - , subq_8.booking__ds_partitioned__extract_quarter - , subq_8.booking__ds_partitioned__extract_month - , subq_8.booking__ds_partitioned__extract_day - , subq_8.booking__ds_partitioned__extract_dow - , subq_8.booking__ds_partitioned__extract_doy - , subq_8.booking__paid_at__day - , subq_8.booking__paid_at__week - , subq_8.booking__paid_at__month - , subq_8.booking__paid_at__quarter - , subq_8.booking__paid_at__year - , subq_8.booking__paid_at__extract_year - , subq_8.booking__paid_at__extract_quarter - , subq_8.booking__paid_at__extract_month - , subq_8.booking__paid_at__extract_day - , subq_8.booking__paid_at__extract_dow - , subq_8.booking__paid_at__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.listing - , subq_8.guest - , subq_8.host - , subq_8.booking__listing - , subq_8.booking__guest - , subq_8.booking__host - , subq_8.is_instant - , subq_8.booking__is_instant - , subq_8.bookings - , subq_8.instant_bookings - , subq_8.booking_value - , subq_8.max_booking_value - , subq_8.min_booking_value - , subq_8.bookers - , subq_8.average_booking_value - , subq_8.referred_bookings - , subq_8.median_booking_value - , subq_8.booking_value_p99 - , subq_8.discrete_booking_value_p99 - , subq_8.approximate_continuous_booking_value_p99 - , subq_8.approximate_discrete_booking_value_p99 + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.ds_partitioned__day + , subq_9.ds_partitioned__week + , subq_9.ds_partitioned__month + , subq_9.ds_partitioned__quarter + , subq_9.ds_partitioned__year + , subq_9.ds_partitioned__extract_year + , subq_9.ds_partitioned__extract_quarter + , subq_9.ds_partitioned__extract_month + , subq_9.ds_partitioned__extract_day + , subq_9.ds_partitioned__extract_dow + , subq_9.ds_partitioned__extract_doy + , subq_9.paid_at__day + , subq_9.paid_at__week + , subq_9.paid_at__month + , subq_9.paid_at__quarter + , subq_9.paid_at__year + , subq_9.paid_at__extract_year + , subq_9.paid_at__extract_quarter + , subq_9.paid_at__extract_month + , subq_9.paid_at__extract_day + , subq_9.paid_at__extract_dow + , subq_9.paid_at__extract_doy + , subq_9.booking__ds__day + , subq_9.booking__ds__week + , subq_9.booking__ds__month + , subq_9.booking__ds__quarter + , subq_9.booking__ds__year + , subq_9.booking__ds__extract_year + , subq_9.booking__ds__extract_quarter + , subq_9.booking__ds__extract_month + , subq_9.booking__ds__extract_day + , subq_9.booking__ds__extract_dow + , subq_9.booking__ds__extract_doy + , subq_9.booking__ds_partitioned__day + , subq_9.booking__ds_partitioned__week + , subq_9.booking__ds_partitioned__month + , subq_9.booking__ds_partitioned__quarter + , subq_9.booking__ds_partitioned__year + , subq_9.booking__ds_partitioned__extract_year + , subq_9.booking__ds_partitioned__extract_quarter + , subq_9.booking__ds_partitioned__extract_month + , subq_9.booking__ds_partitioned__extract_day + , subq_9.booking__ds_partitioned__extract_dow + , subq_9.booking__ds_partitioned__extract_doy + , subq_9.booking__paid_at__day + , subq_9.booking__paid_at__week + , subq_9.booking__paid_at__month + , subq_9.booking__paid_at__quarter + , subq_9.booking__paid_at__year + , subq_9.booking__paid_at__extract_year + , subq_9.booking__paid_at__extract_quarter + , subq_9.booking__paid_at__extract_month + , subq_9.booking__paid_at__extract_day + , subq_9.booking__paid_at__extract_dow + , subq_9.booking__paid_at__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.listing + , subq_9.guest + , subq_9.host + , subq_9.booking__listing + , subq_9.booking__guest + , subq_9.booking__host + , subq_9.is_instant + , subq_9.booking__is_instant + , subq_9.bookings + , subq_9.instant_bookings + , subq_9.booking_value + , subq_9.max_booking_value + , subq_9.min_booking_value + , subq_9.bookers + , subq_9.average_booking_value + , subq_9.referred_bookings + , subq_9.median_booking_value + , subq_9.booking_value_p99 + , subq_9.discrete_booking_value_p99 + , subq_9.approximate_continuous_booking_value_p99 + , subq_9.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -567,25 +599,25 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 - ) subq_10 + ) subq_9 + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__day - , subq_10.metric_time__month - , subq_10.metric_time__year - ) subq_11 - ) subq_12 + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + ) subq_12 + ) subq_13 ON ( - subq_7.metric_time__day = subq_12.metric_time__day + subq_8.metric_time__day = subq_13.metric_time__day ) AND ( - subq_7.metric_time__month = subq_12.metric_time__month + subq_8.metric_time__month = subq_13.metric_time__month ) AND ( - subq_7.metric_time__year = subq_12.metric_time__year + subq_8.metric_time__year = subq_13.metric_time__year ) GROUP BY - COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) - , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) - , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) -) subq_13 + COALESCE(subq_8.metric_time__day, subq_13.metric_time__day) + , COALESCE(subq_8.metric_time__month, subq_13.metric_time__month) + , COALESCE(subq_8.metric_time__year, subq_13.metric_time__year) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql index 93c48480a5..22154d994c 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql @@ -25,31 +25,31 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) AS metric_time__month - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) AS metric_time__year - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) AS metric_time__month + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) AS metric_time__year + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_17.ds - INTERVAL 1 week = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - INTERVAL 1 week = sma_28009_cte.metric_time__day 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 From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] @@ -65,17 +65,17 @@ FROM ( metric_time__day , metric_time__month , metric_time__year - ) subq_25 + ) subq_27 ON ( - subq_21.metric_time__day = subq_25.metric_time__day + subq_23.metric_time__day = subq_27.metric_time__day ) AND ( - subq_21.metric_time__month = subq_25.metric_time__month + subq_23.metric_time__month = subq_27.metric_time__month ) AND ( - subq_21.metric_time__year = subq_25.metric_time__year + subq_23.metric_time__year = subq_27.metric_time__year ) GROUP BY - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) -) subq_26 + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) +) subq_28 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql index 6c2e29f3af..f8ed01d492 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_14.booking__ds__day , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) AS booking__ds__day + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) AS booking__ds__day , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.booking__ds__day - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.booking__ds__day + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.booking__ds__day - , SUM(subq_10.bookings) AS bookings + subq_11.booking__ds__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__ds__day'] SELECT - subq_9.booking__ds__day - , subq_9.bookings + subq_10.booking__ds__day + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -321,7 +321,7 @@ FROM ( , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_dow AS metric_time__extract_dow , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.booking__ds__day AS booking__ds__day + , subq_9.booking__ds__day AS booking__ds__day , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,11 +344,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.booking__ds__day - INTERVAL 14 day = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + subq_9.booking__ds__day - INTERVAL 14 day = subq_6.booking__ds__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_11.booking__ds__day + ) subq_12 + ) subq_13 ON - subq_4.booking__ds__day = subq_12.booking__ds__day + subq_4.booking__ds__day = subq_13.booking__ds__day GROUP BY - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_4.booking__ds__day, subq_13.booking__ds__day) +) subq_14 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql index f89af951e1..71f8c7e514 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0_optimized.sql @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_21.ds - INTERVAL 14 day = sma_28009_cte.booking__ds__day + time_spine_src_28006.ds - INTERVAL 14 day = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql index 8ab0d9ab99..ea7be636da 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql @@ -4,124 +4,124 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day + subq_9.metric_time__day , bookings_5_days_ago AS bookings_5_day_lag FROM ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.bookings AS bookings_5_days_ago + subq_8.metric_time__day + , subq_8.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__day - , SUM(subq_6.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_5.metric_time__day - , subq_5.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Time Range to [2019-12-19T00:00:00, 2020-01-02T00:00:00] SELECT - subq_4.metric_time__day - , subq_4.ds__day - , subq_4.ds__week - , subq_4.ds__month - , subq_4.ds__quarter - , subq_4.ds__year - , subq_4.ds__extract_year - , subq_4.ds__extract_quarter - , subq_4.ds__extract_month - , subq_4.ds__extract_day - , subq_4.ds__extract_dow - , subq_4.ds__extract_doy - , subq_4.ds_partitioned__day - , subq_4.ds_partitioned__week - , subq_4.ds_partitioned__month - , subq_4.ds_partitioned__quarter - , subq_4.ds_partitioned__year - , subq_4.ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy - , subq_4.paid_at__day - , subq_4.paid_at__week - , subq_4.paid_at__month - , subq_4.paid_at__quarter - , subq_4.paid_at__year - , subq_4.paid_at__extract_year - , subq_4.paid_at__extract_quarter - , subq_4.paid_at__extract_month - , subq_4.paid_at__extract_day - , subq_4.paid_at__extract_dow - , subq_4.paid_at__extract_doy - , subq_4.booking__ds__day - , subq_4.booking__ds__week - , subq_4.booking__ds__month - , subq_4.booking__ds__quarter - , subq_4.booking__ds__year - , subq_4.booking__ds__extract_year - , subq_4.booking__ds__extract_quarter - , subq_4.booking__ds__extract_month - , subq_4.booking__ds__extract_day - , subq_4.booking__ds__extract_dow - , subq_4.booking__ds__extract_doy - , subq_4.booking__ds_partitioned__day - , subq_4.booking__ds_partitioned__week - , subq_4.booking__ds_partitioned__month - , subq_4.booking__ds_partitioned__quarter - , subq_4.booking__ds_partitioned__year - , subq_4.booking__ds_partitioned__extract_year - , subq_4.booking__ds_partitioned__extract_quarter - , subq_4.booking__ds_partitioned__extract_month - , subq_4.booking__ds_partitioned__extract_day - , subq_4.booking__ds_partitioned__extract_dow - , subq_4.booking__ds_partitioned__extract_doy - , subq_4.booking__paid_at__day - , subq_4.booking__paid_at__week - , subq_4.booking__paid_at__month - , subq_4.booking__paid_at__quarter - , subq_4.booking__paid_at__year - , subq_4.booking__paid_at__extract_year - , subq_4.booking__paid_at__extract_quarter - , subq_4.booking__paid_at__extract_month - , subq_4.booking__paid_at__extract_day - , subq_4.booking__paid_at__extract_dow - , subq_4.booking__paid_at__extract_doy - , subq_4.metric_time__week - , subq_4.metric_time__month - , subq_4.metric_time__quarter - , subq_4.metric_time__year - , subq_4.metric_time__extract_year - , subq_4.metric_time__extract_quarter - , subq_4.metric_time__extract_month - , subq_4.metric_time__extract_day - , subq_4.metric_time__extract_dow - , subq_4.metric_time__extract_doy - , subq_4.listing - , subq_4.guest - , subq_4.host - , subq_4.booking__listing - , subq_4.booking__guest - , subq_4.booking__host - , subq_4.is_instant - , subq_4.booking__is_instant - , subq_4.bookings - , subq_4.instant_bookings - , subq_4.booking_value - , subq_4.max_booking_value - , subq_4.min_booking_value - , subq_4.bookers - , subq_4.average_booking_value - , subq_4.referred_bookings - , subq_4.median_booking_value - , subq_4.booking_value_p99 - , subq_4.discrete_booking_value_p99 - , subq_4.approximate_continuous_booking_value_p99 - , subq_4.approximate_discrete_booking_value_p99 + subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.ds_partitioned__day + , subq_5.ds_partitioned__week + , subq_5.ds_partitioned__month + , subq_5.ds_partitioned__quarter + , subq_5.ds_partitioned__year + , subq_5.ds_partitioned__extract_year + , subq_5.ds_partitioned__extract_quarter + , subq_5.ds_partitioned__extract_month + , subq_5.ds_partitioned__extract_day + , subq_5.ds_partitioned__extract_dow + , subq_5.ds_partitioned__extract_doy + , subq_5.paid_at__day + , subq_5.paid_at__week + , subq_5.paid_at__month + , subq_5.paid_at__quarter + , subq_5.paid_at__year + , subq_5.paid_at__extract_year + , subq_5.paid_at__extract_quarter + , subq_5.paid_at__extract_month + , subq_5.paid_at__extract_day + , subq_5.paid_at__extract_dow + , subq_5.paid_at__extract_doy + , subq_5.booking__ds__day + , subq_5.booking__ds__week + , subq_5.booking__ds__month + , subq_5.booking__ds__quarter + , subq_5.booking__ds__year + , subq_5.booking__ds__extract_year + , subq_5.booking__ds__extract_quarter + , subq_5.booking__ds__extract_month + , subq_5.booking__ds__extract_day + , subq_5.booking__ds__extract_dow + , subq_5.booking__ds__extract_doy + , subq_5.booking__ds_partitioned__day + , subq_5.booking__ds_partitioned__week + , subq_5.booking__ds_partitioned__month + , subq_5.booking__ds_partitioned__quarter + , subq_5.booking__ds_partitioned__year + , subq_5.booking__ds_partitioned__extract_year + , subq_5.booking__ds_partitioned__extract_quarter + , subq_5.booking__ds_partitioned__extract_month + , subq_5.booking__ds_partitioned__extract_day + , subq_5.booking__ds_partitioned__extract_dow + , subq_5.booking__ds_partitioned__extract_doy + , subq_5.booking__paid_at__day + , subq_5.booking__paid_at__week + , subq_5.booking__paid_at__month + , subq_5.booking__paid_at__quarter + , subq_5.booking__paid_at__year + , subq_5.booking__paid_at__extract_year + , subq_5.booking__paid_at__extract_quarter + , subq_5.booking__paid_at__extract_month + , subq_5.booking__paid_at__extract_day + , subq_5.booking__paid_at__extract_dow + , subq_5.booking__paid_at__extract_doy + , subq_5.metric_time__week + , subq_5.metric_time__month + , subq_5.metric_time__quarter + , subq_5.metric_time__year + , subq_5.metric_time__extract_year + , subq_5.metric_time__extract_quarter + , subq_5.metric_time__extract_month + , subq_5.metric_time__extract_day + , subq_5.metric_time__extract_dow + , subq_5.metric_time__extract_doy + , subq_5.metric_time__day + , subq_5.listing + , subq_5.guest + , subq_5.host + , subq_5.booking__listing + , subq_5.booking__guest + , subq_5.booking__host + , subq_5.is_instant + , subq_5.booking__is_instant + , subq_5.bookings + , subq_5.instant_bookings + , subq_5.booking_value + , subq_5.max_booking_value + , subq_5.min_booking_value + , subq_5.bookers + , subq_5.average_booking_value + , subq_5.referred_bookings + , subq_5.median_booking_value + , subq_5.booking_value_p99 + , subq_5.discrete_booking_value_p99 + , subq_5.approximate_continuous_booking_value_p99 + , subq_5.approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -201,7 +201,7 @@ FROM ( , subq_1.metric_time__extract_day AS metric_time__extract_day , subq_1.metric_time__extract_dow AS metric_time__extract_dow , subq_1.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.metric_time__day AS metric_time__day + , subq_4.metric_time__day AS metric_time__day , subq_1.listing AS listing , subq_1.guest AS guest , subq_1.host AS host @@ -224,11 +224,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -425,12 +457,12 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - WHERE subq_4.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' - ) subq_5 - ) subq_6 + subq_4.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_5 + WHERE subq_5.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' + ) subq_6 + ) subq_7 GROUP BY - subq_6.metric_time__day - ) subq_7 -) subq_8 + subq_7.metric_time__day + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql index 9e6a52124f..749d48dc37 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0_optimized.sql @@ -13,9 +13,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.ds AS metric_time__day - , SUM(subq_10.bookings) AS bookings_5_days_ago - FROM ***************************.mf_time_spine subq_12 + time_spine_src_28006.ds AS metric_time__day + , SUM(subq_11.bookings) AS bookings_5_days_ago + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -23,10 +23,10 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 ON - subq_12.ds - INTERVAL 5 day = subq_10.metric_time__day - WHERE subq_12.ds BETWEEN '2019-12-19' AND '2020-01-02' + time_spine_src_28006.ds - INTERVAL 5 day = subq_11.metric_time__day + WHERE time_spine_src_28006.ds BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_12.ds -) subq_17 + time_spine_src_28006.ds +) subq_19 diff --git a/tests_metricflow/snapshots/test_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 657ae62d6f..27c5a3b0c7 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -539,12 +571,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 c035b82ddb..7bdf364b90 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 4e96546efe..52652753fc 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,50 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__month AS metric_time__month + , subq_2.ds__day + , subq_2.ds__week + , 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__martian_day + 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 +131,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 34b51248ac..6fbfe61c40 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' + -- Change Column Aliases + -- 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 783a3b9c02..1772e56254 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 7dbd0e5edd..1c74ca5b3f 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 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 57f3a81974..d107063888 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,16 +578,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 09a6a5bee2..ce8ed36fb8 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) AS metric_time__week - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) AS metric_time__week + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__week'] @@ -33,26 +33,26 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__week + DATE_TRUNC('week', time_spine_src_28006.ds) AS metric_time__week , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('week', subq_21.ds) = subq_21.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = time_spine_src_28006.ds GROUP BY - DATE_TRUNC('week', subq_21.ds) - ) subq_25 + DATE_TRUNC('week', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__week = subq_25.metric_time__week + subq_19.metric_time__week = subq_27.metric_time__week GROUP BY - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) -) subq_26 + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) +) subq_28 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 612cd1565e..1218c85662 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 f99ceb6912..019512ce5e 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_21.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 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 a3c11f6528..ed7b75c923 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__week + , subq_7.ds__month + , 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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 295343a332..6cc4f03ebc 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) AS metric_time__quarter - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) AS metric_time__quarter + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__quarter'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__quarter + DATE_TRUNC('quarter', time_spine_src_28006.ds) AS metric_time__quarter , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_21.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('quarter', subq_21.ds) - ) subq_25 + DATE_TRUNC('quarter', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__quarter = subq_25.metric_time__quarter + subq_19.metric_time__quarter = subq_27.metric_time__quarter GROUP BY - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) -) subq_26 + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) +) subq_28 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 0d51482767..9282c1f8de 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,236 +362,268 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +716,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 f07274f038..3a017678ac 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 @@ -18,43 +18,43 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) AS metric_time__day - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) AS metric_time__day + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_27.ds - MAKE_INTERVAL(months => 1) = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(months => 1) = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 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 834c12c2f5..ae0f821ebd 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -331,238 +363,270 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , 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__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_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 +719,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 a2221df00f..fc91a0d498 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 @@ -18,44 +18,44 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) AS metric_time__year - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) AS metric_time__year + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds 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_27.ds) AS metric_time__year + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_27.ds - MAKE_INTERVAL(months => 1) = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(months => 1) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('year', subq_27.ds) - ) subq_31 + DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_35 ON - subq_24.metric_time__year = subq_31.metric_time__year + subq_27.metric_time__year = subq_35.metric_time__year GROUP BY - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) -) subq_32 + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) +) subq_36 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 69c1c7eeb0..1e94370ec0 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_8.ds__day AS metric_time__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__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_8 + ) subq_9 + ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -749,17 +781,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 dacf10bdc0..9f517cdd70 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_21.bookings) AS bookings - , MAX(subq_29.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_22.bookings) AS bookings + , MAX(subq_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -35,11 +35,11 @@ FROM ( metric_time__day , bookings FROM sma_28009_cte sma_28009_cte - ) 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'] @@ -51,20 +51,20 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_24.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_24 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_24.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day - ) subq_25 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day + ) subq_27 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_29 + ) subq_31 ON - subq_21.metric_time__day = subq_29.metric_time__day + subq_22.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) +) subq_32 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 ef5e72141a..81780b704b 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -438,10 +470,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 1329a0ade5..3971271456 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 49d2b87f02..d51c12f2c5 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,129 +362,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 +577,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 ad4ca7737b..9ac8ac6276 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 @@ -19,25 +19,25 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_17.ds - MAKE_INTERVAL(weeks => 1) = sma_28009_cte.booking__ds__day + time_spine_src_28006.ds - MAKE_INTERVAL(weeks => 1) = sma_28009_cte.booking__ds__day GROUP BY - subq_17.ds - ) subq_21 + time_spine_src_28006.ds + ) subq_23 FULL OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'booking__ds__day'] @@ -49,9 +49,9 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY booking__ds__day - ) subq_25 + ) subq_27 ON - subq_21.booking__ds__day = subq_25.booking__ds__day + subq_23.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 23f3c3659d..68e5b6bd63 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -324,10 +356,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 814f94c4a2..715adafa67 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 e905ef7773..a2831e873c 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,87 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +164,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 +187,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -356,18 +420,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 c11fef9c79..cd6a43d881 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 84366e4d4d..763de41e1f 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__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__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 + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -245,129 +277,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 +492,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 68b34931cd..fed8434e09 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 @@ -18,15 +18,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_24.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_29.booking_fees) AS booking_fees + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_26.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_31.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 @@ -43,11 +43,11 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) 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 @@ -64,10 +64,10 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) subq_28 - ) subq_29 + ) subq_30 + ) subq_31 ON - subq_24.metric_time__day = subq_29.metric_time__day + subq_26.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) +) subq_32 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 0cbb871dd0..dc5bfedf27 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,71 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +148,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 +171,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -340,14 +404,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 ba241866de..0cf2bf2811 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 37735affcc..f19462ecb7 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 ad70412fd9..47a6aadd20 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 b842031313..d05ab1a1e6 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 0aa067052a..52405830a7 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 743886eea4..de44b7a580 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,13 +460,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 52f737090e..6bc6a33365 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 b4ff6725dc..5f35ae002c 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -336,12 +368,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 321cb4ac6d..bb00b76d51 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 d80383f1b1..5107423103 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 cfc0032b39..526dbc930b 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.booking__ds__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 873e4a30d7..5129d9082d 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -434,232 +466,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 +784,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 065ef437af..6ef13dfc03 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 @@ -22,9 +22,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) AS metric_time__month - , MAX(subq_24.booking_value) AS booking_value - , MAX(subq_29.bookers) AS bookers + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) AS metric_time__month + , MAX(subq_26.booking_value) AS booking_value + , MAX(subq_31.bookers) AS bookers FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__month'] @@ -36,19 +36,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 , sma_28009_cte.booking_value AS booking_value - FROM ***************************.mf_time_spine subq_19 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_19.ds - MAKE_INTERVAL(weeks => 1) = sma_28009_cte.metric_time__day - ) subq_20 + time_spine_src_28006.ds - MAKE_INTERVAL(weeks => 1) = sma_28009_cte.metric_time__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'] @@ -65,13 +65,13 @@ FROM ( , booking_value , bookers FROM sma_28009_cte sma_28009_cte - ) subq_25 + ) subq_27 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_29 + ) subq_31 ON - subq_24.metric_time__month = subq_29.metric_time__month + subq_26.metric_time__month = subq_31.metric_time__month GROUP BY - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) -) subq_30 + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) +) subq_32 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 c38d5049a3..0eccdef2c0 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -344,137 +376,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 +599,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 85e0a88e86..de3f2029cb 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 @@ -25,31 +25,31 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) AS metric_time__month - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) AS metric_time__year - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) AS metric_time__month + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) AS metric_time__year + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_17.ds - MAKE_INTERVAL(weeks => 1) = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(weeks => 1) = sma_28009_cte.metric_time__day 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 From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] @@ -65,17 +65,17 @@ FROM ( metric_time__day , metric_time__month , metric_time__year - ) subq_25 + ) subq_27 ON ( - subq_21.metric_time__day = subq_25.metric_time__day + subq_23.metric_time__day = subq_27.metric_time__day ) AND ( - subq_21.metric_time__month = subq_25.metric_time__month + subq_23.metric_time__month = subq_27.metric_time__month ) AND ( - subq_21.metric_time__year = subq_25.metric_time__year + subq_23.metric_time__year = subq_27.metric_time__year ) GROUP BY - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) -) subq_26 + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) +) subq_28 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 9e29382368..6bd0776312 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 795266bca7..3fd3f64e44 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_21.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.booking__ds__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 6d0b707805..854d7480ed 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -425,12 +457,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 773cb85a3d..1f8335e0a9 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 9b22b1037a..56020f2e92 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -539,12 +571,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 54fdaf9388..bbaf908dcd 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 d16d4843a7..57d9183e45 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,50 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__month AS metric_time__month + , subq_2.ds__day + , subq_2.ds__week + , 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__martian_day + 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 +131,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 9b19e89dbe..368f8bf285 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' + -- Change Column Aliases + -- 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 c299b86a8a..182d26bf2a 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 2cb4a1f1bb..2e88e5a864 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 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 e956f057e5..2097c3f1c8 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,16 +578,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 067ed41ba5..9c7edcc6d1 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) AS metric_time__week - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) AS metric_time__week + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__week'] @@ -33,26 +33,26 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__week + DATE_TRUNC('week', time_spine_src_28006.ds) AS metric_time__week , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('week', subq_21.ds) = subq_21.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = time_spine_src_28006.ds GROUP BY - DATE_TRUNC('week', subq_21.ds) - ) subq_25 + DATE_TRUNC('week', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__week = subq_25.metric_time__week + subq_19.metric_time__week = subq_27.metric_time__week GROUP BY - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) -) subq_26 + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) +) subq_28 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 aad61e85c8..16189e9b54 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 2346816bc4..34ca661d00 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 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 52e6be646e..4f37b04e1f 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__week + , subq_7.ds__month + , 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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 f6adf8e883..9df328ed23 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) AS metric_time__quarter - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) AS metric_time__quarter + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__quarter'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__quarter + DATE_TRUNC('quarter', time_spine_src_28006.ds) AS metric_time__quarter , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('quarter', subq_21.ds) - ) subq_25 + DATE_TRUNC('quarter', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__quarter = subq_25.metric_time__quarter + subq_19.metric_time__quarter = subq_27.metric_time__quarter GROUP BY - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) -) subq_26 + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) +) subq_28 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 d30aaa07eb..a3c9ebfb72 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,236 +362,268 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +716,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 ba8ac53abe..1292c54d78 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 @@ -18,43 +18,43 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) AS metric_time__day - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) AS metric_time__day + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, subq_27.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 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 c0ffbc4b6e..976b311928 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -331,238 +363,270 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , 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__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_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 +719,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 d26c41d45e..6d06b64f19 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 @@ -18,44 +18,44 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) AS metric_time__year - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) AS metric_time__year + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds 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_27.ds) AS metric_time__year + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, subq_27.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('year', subq_27.ds) - ) subq_31 + DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_35 ON - subq_24.metric_time__year = subq_31.metric_time__year + subq_27.metric_time__year = subq_35.metric_time__year GROUP BY - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) -) subq_32 + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) +) subq_36 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 511363bfcf..8f2d254868 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_8.ds__day AS metric_time__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__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_8 + ) subq_9 + ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -749,17 +781,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 9be7e9c696..3c24edc18a 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_21.bookings) AS bookings - , MAX(subq_29.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_22.bookings) AS bookings + , MAX(subq_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -35,11 +35,11 @@ FROM ( metric_time__day , bookings FROM sma_28009_cte sma_28009_cte - ) 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'] @@ -51,20 +51,20 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_24.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_24 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_24.ds) = sma_28009_cte.metric_time__day - ) subq_25 + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_27 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_29 + ) subq_31 ON - subq_21.metric_time__day = subq_29.metric_time__day + subq_22.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) +) subq_32 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 c1818c710a..052ee5b70c 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -438,10 +470,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 28071a31e6..95d7828347 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 6932f490e2..970b9208f5 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,129 +362,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 +577,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 acc120efda..89ce2d6e3b 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 @@ -19,25 +19,25 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(week, -1, subq_17.ds) = sma_28009_cte.booking__ds__day + DATEADD(week, -1, time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_17.ds - ) subq_21 + time_spine_src_28006.ds + ) subq_23 FULL OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'booking__ds__day'] @@ -49,9 +49,9 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY booking__ds__day - ) subq_25 + ) subq_27 ON - subq_21.booking__ds__day = subq_25.booking__ds__day + subq_23.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 b93df27b75..27725a5785 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -324,10 +356,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 6b9a08d0b2..e488fdb3f9 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 9eb7ee2063..a438b93bd0 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,87 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +164,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 +187,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -356,18 +420,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 606a9fa315..e2a58e9666 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 77c4a6146a..0f7a24e815 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__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__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 + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -245,129 +277,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 +492,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 0759325bc6..65b8e0609b 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 @@ -18,15 +18,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_24.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_29.booking_fees) AS booking_fees + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_26.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_31.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 @@ -43,11 +43,11 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) 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 @@ -64,10 +64,10 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) subq_28 - ) subq_29 + ) subq_30 + ) subq_31 ON - subq_24.metric_time__day = subq_29.metric_time__day + subq_26.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) +) subq_32 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 77928c9c0e..e21a9a6ab8 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,71 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +148,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 +171,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -340,14 +404,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 858599a4b1..78c6b87a94 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 6619dd6f25..6e4db61962 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 a0cd96d15d..abff7fdb59 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 b2226271d2..a8689af3de 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 3d6418dab3..b75545623c 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 1042220d4c..05e34bda24 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,13 +460,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 e2ef45757b..6877e3ae67 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 a88c011d0d..664e828140 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -336,12 +368,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 e47d7558aa..778cb9215a 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 fcd1867942..fdac00d4f2 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 8a9761e488..7c08b120ba 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.booking__ds__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 d292518132..d8a6659318 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -434,232 +466,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 +784,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 0b8d941d46..7590afdc1a 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 @@ -22,9 +22,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) AS metric_time__month - , MAX(subq_24.booking_value) AS booking_value - , MAX(subq_29.bookers) AS bookers + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) AS metric_time__month + , MAX(subq_26.booking_value) AS booking_value + , MAX(subq_31.bookers) AS bookers FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__month'] @@ -36,19 +36,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 , sma_28009_cte.booking_value AS booking_value - FROM ***************************.mf_time_spine subq_19 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(week, -1, subq_19.ds) = sma_28009_cte.metric_time__day - ) subq_20 + DATEADD(week, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__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'] @@ -65,13 +65,13 @@ FROM ( , booking_value , bookers FROM sma_28009_cte sma_28009_cte - ) subq_25 + ) subq_27 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_29 + ) subq_31 ON - subq_24.metric_time__month = subq_29.metric_time__month + subq_26.metric_time__month = subq_31.metric_time__month GROUP BY - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) -) subq_30 + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) +) subq_32 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 8d3d0df119..b5fc46108d 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -344,137 +376,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 +599,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 f6a3c5ac66..f00e5ec515 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 @@ -25,31 +25,31 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) AS metric_time__month - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) AS metric_time__year - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) AS metric_time__month + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) AS metric_time__year + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(week, -1, subq_17.ds) = sma_28009_cte.metric_time__day + DATEADD(week, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day 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 From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] @@ -65,17 +65,17 @@ FROM ( metric_time__day , metric_time__month , metric_time__year - ) subq_25 + ) subq_27 ON ( - subq_21.metric_time__day = subq_25.metric_time__day + subq_23.metric_time__day = subq_27.metric_time__day ) AND ( - subq_21.metric_time__month = subq_25.metric_time__month + subq_23.metric_time__month = subq_27.metric_time__month ) AND ( - subq_21.metric_time__year = subq_25.metric_time__year + subq_23.metric_time__year = subq_27.metric_time__year ) GROUP BY - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) -) subq_26 + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) +) subq_28 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 d6994b9aa2..6d69a19680 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 c630483bd6..dce7a889cf 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.booking__ds__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 9ff738e788..b3dee58d70 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -425,12 +457,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 eb8f6a54d0..ab218ad8f9 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 6a112a6e5b..a93e601109 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -539,12 +571,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 f20bb5198f..5929f7bc2f 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 b1c9634d3a..6b4b0ccc6d 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,50 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__month AS metric_time__month + , subq_2.ds__day + , subq_2.ds__week + , 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__martian_day + 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 +131,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 198624f2fc..37d9acb1c7 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' + -- Change Column Aliases + -- 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 8c9de2b854..bb40e9625c 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 e1d7156576..2eccdc3199 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 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 093d19c38d..11f9dc8c98 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,16 +578,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 b28e83c8c6..315b9b2b3c 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) AS metric_time__week - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) AS metric_time__week + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__week'] @@ -33,26 +33,26 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__week + DATE_TRUNC('week', time_spine_src_28006.ds) AS metric_time__week , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('week', subq_21.ds) = subq_21.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = time_spine_src_28006.ds GROUP BY - DATE_TRUNC('week', subq_21.ds) - ) subq_25 + DATE_TRUNC('week', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__week = subq_25.metric_time__week + subq_19.metric_time__week = subq_27.metric_time__week GROUP BY - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) -) subq_26 + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) +) subq_28 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 7217c53603..3dcb28a78c 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 21fc075b2a..5d00cceac5 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 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 2fb4b0f8cb..8970e9b9d5 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__week + , subq_7.ds__month + , 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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 4a7e2de57d..53db40714a 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) AS metric_time__quarter - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) AS metric_time__quarter + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__quarter'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__quarter + DATE_TRUNC('quarter', time_spine_src_28006.ds) AS metric_time__quarter , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('quarter', subq_21.ds) - ) subq_25 + DATE_TRUNC('quarter', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__quarter = subq_25.metric_time__quarter + subq_19.metric_time__quarter = subq_27.metric_time__quarter GROUP BY - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) -) subq_26 + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) +) subq_28 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 9b94279745..65b53667ef 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,236 +362,268 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +716,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 5e34b93bc5..4c95cb1435 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 @@ -18,43 +18,43 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) AS metric_time__day - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) AS metric_time__day + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, subq_27.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 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 ddf8b95558..09ec10dc8f 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -331,238 +363,270 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , 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__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_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 +719,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 972c06326c..8b847c8492 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 @@ -18,44 +18,44 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) AS metric_time__year - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) AS metric_time__year + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds 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_27.ds) AS metric_time__year + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(month, -1, subq_27.ds) = sma_28009_cte.metric_time__day + DATEADD(month, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('year', subq_27.ds) - ) subq_31 + DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_35 ON - subq_24.metric_time__year = subq_31.metric_time__year + subq_27.metric_time__year = subq_35.metric_time__year GROUP BY - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) -) subq_32 + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) +) subq_36 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 e8efb7582a..4cd15174cb 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_8.ds__day AS metric_time__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__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_8 + ) subq_9 + ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -749,17 +781,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 ddf935e110..b777d29834 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_21.bookings) AS bookings - , MAX(subq_29.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_22.bookings) AS bookings + , MAX(subq_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -35,11 +35,11 @@ FROM ( metric_time__day , bookings FROM sma_28009_cte sma_28009_cte - ) 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'] @@ -51,20 +51,20 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_24.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_24 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_24.ds) = sma_28009_cte.metric_time__day - ) subq_25 + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_27 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_29 + ) subq_31 ON - subq_21.metric_time__day = subq_29.metric_time__day + subq_22.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) +) subq_32 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 a0c24f4ad8..6cdc822f78 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -438,10 +470,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 3776496f57..daf33313bf 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 5414acdf40..724b912492 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,129 +362,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 +577,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 f19ab2542b..17ffeec7dc 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 @@ -19,25 +19,25 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(week, -1, subq_17.ds) = sma_28009_cte.booking__ds__day + DATEADD(week, -1, time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_17.ds - ) subq_21 + time_spine_src_28006.ds + ) subq_23 FULL OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'booking__ds__day'] @@ -49,9 +49,9 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY booking__ds__day - ) subq_25 + ) subq_27 ON - subq_21.booking__ds__day = subq_25.booking__ds__day + subq_23.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 460c155b07..e83b26a6f3 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -324,10 +356,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 a603ed6aaf..915d96de67 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 0d33e40462..da873f5dea 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,87 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +164,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 +187,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -356,18 +420,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 9388c1fcc3..be9fa2df7a 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 afbe9604b6..5438bde9cc 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__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__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 + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -245,129 +277,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 +492,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 d1c5ade38c..080c3fc4bf 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 @@ -18,15 +18,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_24.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_29.booking_fees) AS booking_fees + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_26.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_31.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 @@ -43,11 +43,11 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) 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 @@ -64,10 +64,10 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) subq_28 - ) subq_29 + ) subq_30 + ) subq_31 ON - subq_24.metric_time__day = subq_29.metric_time__day + subq_26.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) +) subq_32 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 dde312e101..f63d74d7d3 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,71 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +148,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 +171,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -340,14 +404,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 f750dc6487..b21ee2333a 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 4b8fa3ee3a..612fdf2ffb 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 68d9df1848..96fb239f13 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 0942c73ff9..83bae5fd79 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 d23fbf4a14..1b0f2830a4 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 43431536dc..214a58d167 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,13 +460,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 2fec95707b..39d096eebf 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 d01f96513f..f842a708d4 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -336,12 +368,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 d270f22808..44ec893a1e 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 cb56bf5553..23a58321bd 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 32f09cd456..b327593717 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.booking__ds__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 38eae4d798..b2d078c006 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -434,232 +466,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 +784,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 0367cbfb81..e6a02a404d 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 @@ -22,9 +22,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) AS metric_time__month - , MAX(subq_24.booking_value) AS booking_value - , MAX(subq_29.bookers) AS bookers + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) AS metric_time__month + , MAX(subq_26.booking_value) AS booking_value + , MAX(subq_31.bookers) AS bookers FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__month'] @@ -36,19 +36,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 , sma_28009_cte.booking_value AS booking_value - FROM ***************************.mf_time_spine subq_19 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(week, -1, subq_19.ds) = sma_28009_cte.metric_time__day - ) subq_20 + DATEADD(week, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__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'] @@ -65,13 +65,13 @@ FROM ( , booking_value , bookers FROM sma_28009_cte sma_28009_cte - ) subq_25 + ) subq_27 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_29 + ) subq_31 ON - subq_24.metric_time__month = subq_29.metric_time__month + subq_26.metric_time__month = subq_31.metric_time__month GROUP BY - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) -) subq_30 + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) +) subq_32 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 c6bfc372c3..44b1df1c8e 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -344,137 +376,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 +599,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 2f1cddd02b..81e8a53514 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 @@ -25,31 +25,31 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) AS metric_time__month - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) AS metric_time__year - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) AS metric_time__month + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) AS metric_time__year + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(week, -1, subq_17.ds) = sma_28009_cte.metric_time__day + DATEADD(week, -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day 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 From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] @@ -65,17 +65,17 @@ FROM ( metric_time__day , metric_time__month , metric_time__year - ) subq_25 + ) subq_27 ON ( - subq_21.metric_time__day = subq_25.metric_time__day + subq_23.metric_time__day = subq_27.metric_time__day ) AND ( - subq_21.metric_time__month = subq_25.metric_time__month + subq_23.metric_time__month = subq_27.metric_time__month ) AND ( - subq_21.metric_time__year = subq_25.metric_time__year + subq_23.metric_time__year = subq_27.metric_time__year ) GROUP BY - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) -) subq_26 + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) +) subq_28 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 8637158587..9f75de0e79 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 57da68d53e..8b86124ed7 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.booking__ds__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 131df56136..1685d28609 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -425,12 +457,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 ca27d77027..9e7c4ff455 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 c2f529376d..ca7e2f5a6d 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -539,12 +571,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 c74bc63f1d..e3963f89f6 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 782826cc2b..baa085b5ac 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,50 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__month AS metric_time__month + , subq_2.ds__day + , subq_2.ds__week + , 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__martian_day + 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 +131,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 7a98c4a7dd..e47cd140d8 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' + -- Change Column Aliases + -- 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 252cd8290d..8e4ff62826 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 79a64fc741..cbd7207967 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 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 25ee9554a8..2d5130454e 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__week AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,16 +578,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 04c6036dd8..c93b22d6c9 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) AS metric_time__week - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) AS metric_time__week + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__week'] @@ -33,26 +33,26 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__week + DATE_TRUNC('week', time_spine_src_28006.ds) AS metric_time__week , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('week', subq_21.ds) = subq_21.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('week', time_spine_src_28006.ds) = time_spine_src_28006.ds GROUP BY - DATE_TRUNC('week', subq_21.ds) - ) subq_25 + DATE_TRUNC('week', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__week = subq_25.metric_time__week + subq_19.metric_time__week = subq_27.metric_time__week GROUP BY - COALESCE(subq_18.metric_time__week, subq_25.metric_time__week) -) subq_26 + COALESCE(subq_19.metric_time__week, subq_27.metric_time__week) +) subq_28 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 92809b655f..b7f3ccf9bb 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 c4626b2b97..15b7c593ab 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('day', -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.metric_time__day = subq_25.metric_time__day + subq_19.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_25.metric_time__day) -) subq_26 + COALESCE(subq_19.metric_time__day, subq_27.metric_time__day) +) subq_28 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 55707852fe..99402f2d85 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__quarter AS metric_time__quarter + , subq_7.ds__week + , subq_7.ds__month + , 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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 7683ccc25e..1aed0092c1 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) AS metric_time__quarter - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) AS metric_time__quarter + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__quarter'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__quarter + DATE_TRUNC('quarter', time_spine_src_28006.ds) AS metric_time__quarter , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('day', -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('quarter', subq_21.ds) - ) subq_25 + DATE_TRUNC('quarter', time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__quarter = subq_25.metric_time__quarter + subq_19.metric_time__quarter = subq_27.metric_time__quarter GROUP BY - COALESCE(subq_18.metric_time__quarter, subq_25.metric_time__quarter) -) subq_26 + COALESCE(subq_19.metric_time__quarter, subq_27.metric_time__quarter) +) subq_28 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 07820dc20b..20c6c7373a 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,236 +362,268 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +716,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 e7da94be59..f5a5f9b9a9 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 @@ -18,43 +18,43 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) AS metric_time__day - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) AS metric_time__day + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('month', -1, subq_27.ds) = sma_28009_cte.metric_time__day + DATE_ADD('month', -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 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 1388092eb8..bf94ae2594 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__year AS metric_time__year + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -331,238 +363,270 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__day + , subq_11.ds__year AS metric_time__year + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , 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__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_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 +719,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 33ec24fb3c..0e82437efe 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 @@ -18,44 +18,44 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) AS metric_time__year - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_31.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) AS metric_time__year + , MAX(subq_27.month_start_bookings) AS month_start_bookings + , MAX(subq_35.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 + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_20.ds) = sma_28009_cte.metric_time__day - WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + WHERE DATE_TRUNC('year', time_spine_src_28006.ds) = time_spine_src_28006.ds 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_27.ds) AS metric_time__year + DATE_TRUNC('year', time_spine_src_28006.ds) AS metric_time__year , SUM(sma_28009_cte.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('month', -1, subq_27.ds) = sma_28009_cte.metric_time__day + DATE_ADD('month', -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - DATE_TRUNC('year', subq_27.ds) - ) subq_31 + DATE_TRUNC('year', time_spine_src_28006.ds) + ) subq_35 ON - subq_24.metric_time__year = subq_31.metric_time__year + subq_27.metric_time__year = subq_35.metric_time__year GROUP BY - COALESCE(subq_24.metric_time__year, subq_31.metric_time__year) -) subq_32 + COALESCE(subq_27.metric_time__year, subq_35.metric_time__year) +) subq_36 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 6cd2eb1c48..4d1f913e66 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_8.ds__day AS metric_time__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__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_8 + ) subq_9 + ) subq_10 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -749,17 +781,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 30cbffa90c..d823bd1402 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_21.bookings) AS bookings - , MAX(subq_29.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_22.bookings) AS bookings + , MAX(subq_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -35,11 +35,11 @@ FROM ( metric_time__day , bookings FROM sma_28009_cte sma_28009_cte - ) 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'] @@ -51,20 +51,20 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_24.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_24 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('day', -14, subq_24.ds) = sma_28009_cte.metric_time__day - ) subq_25 + DATE_ADD('day', -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_27 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_29 + ) subq_31 ON - subq_21.metric_time__day = subq_29.metric_time__day + subq_22.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_21.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_22.metric_time__day, subq_31.metric_time__day) +) subq_32 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 6d72a2d186..5bad02fcf4 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 INNER JOIN ( -- Join Self Over Time Range SELECT @@ -438,10 +470,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 c9431a6e52..0838604a60 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 128caed9bb..5b66eba121 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS booking__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -330,129 +362,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 +577,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 f8ae325ac2..7869d08728 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 @@ -19,25 +19,25 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('week', -1, subq_17.ds) = sma_28009_cte.booking__ds__day + DATE_ADD('week', -1, time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_17.ds - ) subq_21 + time_spine_src_28006.ds + ) subq_23 FULL OUTER JOIN ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'booking__ds__day'] @@ -49,9 +49,9 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY booking__ds__day - ) subq_25 + ) subq_27 ON - subq_21.booking__ds__day = subq_25.booking__ds__day + subq_23.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_21.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_23.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 3005aefe06..ccc706a19d 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -324,10 +356,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 bb78d05bf8..cd55e4b0da 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 72065e71c3..78893ab73d 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,87 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +164,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 +187,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -356,18 +420,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 8adb624ace..01dab6b8e5 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 761d599285..64f91d6dea 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,57 @@ 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 ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__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__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 + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -245,129 +277,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 +492,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 3b14b01d21..3c722f0e31 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 @@ -18,15 +18,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) AS metric_time__day - , MAX(subq_24.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_29.booking_fees) AS booking_fees + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , MAX(subq_26.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_31.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 @@ -43,11 +43,11 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) 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 @@ -64,10 +64,10 @@ FROM ( FROM sma_28009_cte sma_28009_cte GROUP BY metric_time__day - ) subq_28 - ) subq_29 + ) subq_30 + ) subq_31 ON - subq_24.metric_time__day = subq_29.metric_time__day + subq_26.metric_time__day = subq_31.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_29.metric_time__day) -) subq_30 + COALESCE(subq_26.metric_time__day, subq_31.metric_time__day) +) subq_32 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 81b96798ce..bb5b0037bc 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,71 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +148,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 +171,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -340,14 +404,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 02db30d704..e59300d868 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 2a720cd404..3e86d584bc 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 8bb73428b0..b3018cd737 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 c077b8eaf2..760def82c7 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,76 @@ 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 ( + -- Change Column Aliases + SELECT + subq_10.ds__day AS metric_time__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__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_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 +153,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 +176,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -345,16 +409,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 eda2cec264..38d6d2753d 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 8bbd7d99dd..7fde19919b 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -428,13 +460,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 600f39647f..551977838f 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 3f7983fed3..e535958381 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -336,12 +368,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 88c1ed0b75..e59051e4a3 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 47acb13a2e..15805d20ef 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 7519097eef..e934169d12 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_TRUNC('month', subq_21.ds) = sma_28009_cte.booking__ds__day + DATE_TRUNC('month', time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 dd9bb9335a..d68ba86524 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__day + , subq_2.ds__month AS metric_time__month + , subq_2.ds__week + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -434,232 +466,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 +784,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 0b0f98372d..2d3aada7d5 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 @@ -22,9 +22,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) AS metric_time__month - , MAX(subq_24.booking_value) AS booking_value - , MAX(subq_29.bookers) AS bookers + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) AS metric_time__month + , MAX(subq_26.booking_value) AS booking_value + , MAX(subq_31.bookers) AS bookers FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__month'] @@ -36,19 +36,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 , sma_28009_cte.booking_value AS booking_value - FROM ***************************.mf_time_spine subq_19 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('week', -1, subq_19.ds) = sma_28009_cte.metric_time__day - ) subq_20 + DATE_ADD('week', -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__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'] @@ -65,13 +65,13 @@ FROM ( , booking_value , bookers FROM sma_28009_cte sma_28009_cte - ) subq_25 + ) subq_27 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_29 + ) subq_31 ON - subq_24.metric_time__month = subq_29.metric_time__month + subq_26.metric_time__month = subq_31.metric_time__month GROUP BY - COALESCE(subq_24.metric_time__month, subq_29.metric_time__month) -) subq_30 + COALESCE(subq_26.metric_time__month, subq_31.metric_time__month) +) subq_32 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 6f337acc8e..a578445a7f 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,45 @@ 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 ( + -- Change Column Aliases + 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__week + , subq_2.ds__quarter + , 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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -344,137 +376,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 +599,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 773d930838..31ab03c38f 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 @@ -25,31 +25,31 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) AS metric_time__day - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) AS metric_time__month - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) AS metric_time__year - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_25.bookers) AS bookers + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) AS metric_time__month + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) AS metric_time__year + , MAX(subq_23.booking_value) AS booking_value + , MAX(subq_27.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(sma_28009_cte.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('week', -1, subq_17.ds) = sma_28009_cte.metric_time__day + DATE_ADD('week', -1, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day 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 From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] @@ -65,17 +65,17 @@ FROM ( metric_time__day , metric_time__month , metric_time__year - ) subq_25 + ) subq_27 ON ( - subq_21.metric_time__day = subq_25.metric_time__day + subq_23.metric_time__day = subq_27.metric_time__day ) AND ( - subq_21.metric_time__month = subq_25.metric_time__month + subq_23.metric_time__month = subq_27.metric_time__month ) AND ( - subq_21.metric_time__year = subq_25.metric_time__year + subq_23.metric_time__year = subq_27.metric_time__year ) GROUP BY - COALESCE(subq_21.metric_time__day, subq_25.metric_time__day) - , COALESCE(subq_21.metric_time__month, subq_25.metric_time__month) - , COALESCE(subq_21.metric_time__year, subq_25.metric_time__year) -) subq_26 + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) + , COALESCE(subq_23.metric_time__month, subq_27.metric_time__month) + , COALESCE(subq_23.metric_time__year, subq_27.metric_time__year) +) subq_28 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 b6d85b7bef..6e306603fa 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS booking__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__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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -545,15 +577,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 cc30227e95..164ffca118 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) AS booking__ds__day + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -32,25 +32,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds AS booking__ds__day + time_spine_src_28006.ds AS booking__ds__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('day', -14, subq_21.ds) = sma_28009_cte.booking__ds__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = sma_28009_cte.booking__ds__day GROUP BY - subq_21.ds - ) subq_25 + time_spine_src_28006.ds + ) subq_27 ON - subq_18.booking__ds__day = subq_25.booking__ds__day + subq_19.booking__ds__day = subq_27.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_25.booking__ds__day) -) subq_26 + COALESCE(subq_19.booking__ds__day, subq_27.booking__ds__day) +) subq_28 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 0b6a48e463..d84a55f5ee 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ds__day AS metric_time__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__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_2 + ) subq_3 + ) subq_4 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -425,12 +457,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 db938122af..dee7544e93 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_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..1363607ee0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +metric_time__martian_day bookings_join_to_time_spine +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..c980e19fb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/BigQuery/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +metric_time__day bookings_join_to_time_spine +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..1363607ee0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +metric_time__martian_day bookings_join_to_time_spine +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..c980e19fb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Databricks/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +metric_time__day bookings_join_to_time_spine +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..1363607ee0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +metric_time__martian_day bookings_join_to_time_spine +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..c980e19fb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +metric_time__day bookings_join_to_time_spine +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..1363607ee0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +metric_time__martian_day bookings_join_to_time_spine +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..c980e19fb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Postgres/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +metric_time__day bookings_join_to_time_spine +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..1363607ee0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +metric_time__martian_day bookings_join_to_time_spine +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..c980e19fb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Redshift/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +metric_time__day bookings_join_to_time_spine +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt new file mode 100644 index 0000000000..64dffa1ece --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter__query_output.txt @@ -0,0 +1,6 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter +test_filename: test_fill_nulls_with_0.py +--- +METRIC_TIME__MARTIAN_DAY BOOKINGS_JOIN_TO_TIME_SPINE +-------------------------- ----------------------------- +2020-01-08T00:00:00 46 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..d5ed44764d --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/Snowflake/test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by__query_output.txt @@ -0,0 +1,1005 @@ +test_name: test_join_to_timespine_metric_with_custom_granularity_filter_not_in_group_by +test_filename: test_fill_nulls_with_0.py +--- +METRIC_TIME__DAY BOOKINGS_JOIN_TO_TIME_SPINE +------------------- ----------------------------- +2019-03-02T00:00:00 None +2019-03-03T00:00:00 None +2019-03-04T00:00:00 None +2019-03-05T00:00:00 None +2019-03-06T00:00:00 None +2019-03-07T00:00:00 None +2019-03-08T00:00:00 None +2019-03-09T00:00:00 None +2019-03-10T00:00:00 None +2019-03-11T00:00:00 None +2019-03-12T00:00:00 None +2019-03-13T00:00:00 None +2019-03-14T00:00:00 None +2019-03-15T00:00:00 None +2019-03-16T00:00:00 None +2019-03-17T00:00:00 None +2019-03-18T00:00:00 None +2019-03-19T00:00:00 None +2019-03-20T00:00:00 None +2019-03-21T00:00:00 None +2019-03-22T00:00:00 None +2019-03-23T00:00:00 None +2019-03-24T00:00:00 None +2019-03-25T00:00:00 None +2019-03-26T00:00:00 None +2019-03-27T00:00:00 None +2019-03-28T00:00:00 None +2019-03-29T00:00:00 None +2019-03-30T00:00:00 None +2019-03-31T00:00:00 None +2019-04-01T00:00:00 None +2019-04-02T00:00:00 None +2019-04-03T00:00:00 None +2019-04-04T00:00:00 None +2019-04-05T00:00:00 None +2019-04-06T00:00:00 None +2019-04-07T00:00:00 None +2019-04-08T00:00:00 None +2019-04-09T00:00:00 None +2019-04-10T00:00:00 None +2019-04-11T00:00:00 None +2019-04-12T00:00:00 None +2019-04-13T00:00:00 None +2019-04-14T00:00:00 None +2019-04-15T00:00:00 None +2019-04-16T00:00:00 None +2019-04-17T00:00:00 None +2019-04-18T00:00:00 None +2019-04-19T00:00:00 None +2019-04-20T00:00:00 None +2019-04-21T00:00:00 None +2019-04-22T00:00:00 None +2019-04-23T00:00:00 None +2019-04-24T00:00:00 None +2019-04-25T00:00:00 None +2019-04-26T00:00:00 None +2019-04-27T00:00:00 None +2019-04-28T00:00:00 None +2019-04-29T00:00:00 None +2019-04-30T00:00:00 None +2019-05-01T00:00:00 None +2019-05-02T00:00:00 None +2019-05-03T00:00:00 None +2019-05-04T00:00:00 None +2019-05-05T00:00:00 None +2019-05-06T00:00:00 None +2019-05-07T00:00:00 None +2019-05-08T00:00:00 None +2019-05-09T00:00:00 None +2019-05-10T00:00:00 None +2019-05-11T00:00:00 None +2019-05-12T00:00:00 None +2019-05-13T00:00:00 None +2019-05-14T00:00:00 None +2019-05-15T00:00:00 None +2019-05-16T00:00:00 None +2019-05-17T00:00:00 None +2019-05-18T00:00:00 None +2019-05-19T00:00:00 None +2019-05-20T00:00:00 None +2019-05-21T00:00:00 None +2019-05-22T00:00:00 None +2019-05-23T00:00:00 None +2019-05-24T00:00:00 None +2019-05-25T00:00:00 None +2019-05-26T00:00:00 None +2019-05-27T00:00:00 None +2019-05-28T00:00:00 None +2019-05-29T00:00:00 None +2019-05-30T00:00:00 None +2019-05-31T00:00:00 None +2019-06-01T00:00:00 None +2019-06-02T00:00:00 None +2019-06-03T00:00:00 None +2019-06-04T00:00:00 None +2019-06-05T00:00:00 None +2019-06-06T00:00:00 None +2019-06-07T00:00:00 None +2019-06-08T00:00:00 None +2019-06-09T00:00:00 None +2019-06-10T00:00:00 None +2019-06-11T00:00:00 None +2019-06-12T00:00:00 None +2019-06-13T00:00:00 None +2019-06-14T00:00:00 None +2019-06-15T00:00:00 None +2019-06-16T00:00:00 None +2019-06-17T00:00:00 None +2019-06-18T00:00:00 None +2019-06-19T00:00:00 None +2019-06-20T00:00:00 None +2019-06-21T00:00:00 None +2019-06-22T00:00:00 None +2019-06-23T00:00:00 None +2019-06-24T00:00:00 None +2019-06-25T00:00:00 None +2019-06-26T00:00:00 None +2019-06-27T00:00:00 None +2019-06-28T00:00:00 None +2019-06-29T00:00:00 None +2019-06-30T00:00:00 None +2019-07-01T00:00:00 None +2019-07-02T00:00:00 None +2019-07-03T00:00:00 None +2019-07-04T00:00:00 None +2019-07-05T00:00:00 None +2019-07-06T00:00:00 None +2019-07-07T00:00:00 None +2019-07-08T00:00:00 None +2019-07-09T00:00:00 None +2019-07-10T00:00:00 None +2019-07-11T00:00:00 None +2019-07-12T00:00:00 None +2019-07-13T00:00:00 None +2019-07-14T00:00:00 None +2019-07-15T00:00:00 None +2019-07-16T00:00:00 None +2019-07-17T00:00:00 None +2019-07-18T00:00:00 None +2019-07-19T00:00:00 None +2019-07-20T00:00:00 None +2019-07-21T00:00:00 None +2019-07-22T00:00:00 None +2019-07-23T00:00:00 None +2019-07-24T00:00:00 None +2019-07-25T00:00:00 None +2019-07-26T00:00:00 None +2019-07-27T00:00:00 None +2019-07-28T00:00:00 None +2019-07-29T00:00:00 None +2019-07-30T00:00:00 None +2019-07-31T00:00:00 None +2019-08-01T00:00:00 None +2019-08-02T00:00:00 None +2019-08-03T00:00:00 None +2019-08-04T00:00:00 None +2019-08-05T00:00:00 None +2019-08-06T00:00:00 None +2019-08-07T00:00:00 None +2019-08-08T00:00:00 None +2019-08-09T00:00:00 None +2019-08-10T00:00:00 None +2019-08-11T00:00:00 None +2019-08-12T00:00:00 None +2019-08-13T00:00:00 None +2019-08-14T00:00:00 None +2019-08-15T00:00:00 None +2019-08-16T00:00:00 None +2019-08-17T00:00:00 None +2019-08-18T00:00:00 None +2019-08-19T00:00:00 None +2019-08-20T00:00:00 None +2019-08-21T00:00:00 None +2019-08-22T00:00:00 None +2019-08-23T00:00:00 None +2019-08-24T00:00:00 None +2019-08-25T00:00:00 None +2019-08-26T00:00:00 None +2019-08-27T00:00:00 None +2019-08-28T00:00:00 None +2019-08-29T00:00:00 None +2019-08-30T00:00:00 None +2019-08-31T00:00:00 None +2019-09-01T00:00:00 None +2019-09-02T00:00:00 None +2019-09-03T00:00:00 None +2019-09-04T00:00:00 None +2019-09-05T00:00:00 None +2019-09-06T00:00:00 None +2019-09-07T00:00:00 None +2019-09-08T00:00:00 None +2019-09-09T00:00:00 None +2019-09-10T00:00:00 None +2019-09-11T00:00:00 None +2019-09-12T00:00:00 None +2019-09-13T00:00:00 None +2019-09-14T00:00:00 None +2019-09-15T00:00:00 None +2019-09-16T00:00:00 None +2019-09-17T00:00:00 None +2019-09-18T00:00:00 None +2019-09-19T00:00:00 None +2019-09-20T00:00:00 None +2019-09-21T00:00:00 None +2019-09-22T00:00:00 None +2019-09-23T00:00:00 None +2019-09-24T00:00:00 None +2019-09-25T00:00:00 None +2019-09-26T00:00:00 None +2019-09-27T00:00:00 None +2019-09-28T00:00:00 None +2019-09-29T00:00:00 None +2019-09-30T00:00:00 None +2019-10-01T00:00:00 None +2019-10-02T00:00:00 None +2019-10-03T00:00:00 None +2019-10-04T00:00:00 None +2019-10-05T00:00:00 None +2019-10-06T00:00:00 None +2019-10-07T00:00:00 None +2019-10-08T00:00:00 None +2019-10-09T00:00:00 None +2019-10-10T00:00:00 None +2019-10-11T00:00:00 None +2019-10-12T00:00:00 None +2019-10-13T00:00:00 None +2019-10-14T00:00:00 None +2019-10-15T00:00:00 None +2019-10-16T00:00:00 None +2019-10-17T00:00:00 None +2019-10-18T00:00:00 None +2019-10-19T00:00:00 None +2019-10-20T00:00:00 None +2019-10-21T00:00:00 None +2019-10-22T00:00:00 None +2019-10-23T00:00:00 None +2019-10-24T00:00:00 None +2019-10-25T00:00:00 None +2019-10-26T00:00:00 None +2019-10-27T00:00:00 None +2019-10-28T00:00:00 None +2019-10-29T00:00:00 None +2019-10-30T00:00:00 None +2019-10-31T00:00:00 None +2019-11-01T00:00:00 None +2019-11-02T00:00:00 None +2019-11-03T00:00:00 None +2019-11-04T00:00:00 None +2019-11-05T00:00:00 None +2019-11-06T00:00:00 None +2019-11-07T00:00:00 None +2019-11-08T00:00:00 None +2019-11-09T00:00:00 None +2019-11-10T00:00:00 None +2019-11-11T00:00:00 None +2019-11-12T00:00:00 None +2019-11-13T00:00:00 None +2019-11-14T00:00:00 None +2019-11-15T00:00:00 None +2019-11-16T00:00:00 None +2019-11-17T00:00:00 None +2019-11-18T00:00:00 None +2019-11-19T00:00:00 None +2019-11-20T00:00:00 None +2019-11-21T00:00:00 None +2019-11-22T00:00:00 None +2019-11-23T00:00:00 None +2019-11-24T00:00:00 None +2019-11-25T00:00:00 None +2019-11-26T00:00:00 None +2019-11-27T00:00:00 None +2019-11-28T00:00:00 None +2019-11-29T00:00:00 None +2019-11-30T00:00:00 None +2019-12-01T00:00:00 1 +2019-12-02T00:00:00 None +2019-12-03T00:00:00 None +2019-12-04T00:00:00 None +2019-12-05T00:00:00 None +2019-12-06T00:00:00 None +2019-12-07T00:00:00 None +2019-12-08T00:00:00 None +2019-12-09T00:00:00 None +2019-12-10T00:00:00 None +2019-12-11T00:00:00 None +2019-12-12T00:00:00 None +2019-12-13T00:00:00 None +2019-12-14T00:00:00 None +2019-12-15T00:00:00 None +2019-12-16T00:00:00 None +2019-12-17T00:00:00 None +2019-12-18T00:00:00 10 +2019-12-19T00:00:00 18 +2019-12-20T00:00:00 2 +2019-12-21T00:00:00 None +2019-12-22T00:00:00 None +2019-12-23T00:00:00 None +2019-12-24T00:00:00 None +2019-12-25T00:00:00 None +2019-12-26T00:00:00 None +2019-12-27T00:00:00 None +2019-12-28T00:00:00 None +2019-12-29T00:00:00 None +2019-12-30T00:00:00 None +2019-12-31T00:00:00 None +2020-01-01T00:00:00 5 +2020-01-02T00:00:00 9 +2020-01-03T00:00:00 1 +2020-01-04T00:00:00 None +2020-01-05T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 None +2020-01-08T00:00:00 None +2020-01-09T00:00:00 None +2020-01-10T00:00:00 None +2020-01-11T00:00:00 None +2020-01-12T00:00:00 None +2020-01-13T00:00:00 None +2020-01-14T00:00:00 None +2020-01-15T00:00:00 None +2020-01-16T00:00:00 None +2020-01-17T00:00:00 None +2020-01-18T00:00:00 None +2020-01-19T00:00:00 None +2020-01-20T00:00:00 None +2020-01-21T00:00:00 None +2020-01-22T00:00:00 None +2020-01-23T00:00:00 None +2020-01-24T00:00:00 None +2020-01-25T00:00:00 None +2020-01-26T00:00:00 None +2020-01-27T00:00:00 None +2020-01-28T00:00:00 None +2020-01-29T00:00:00 None +2020-01-30T00:00:00 None +2020-01-31T00:00:00 None +2020-02-01T00:00:00 None +2020-02-02T00:00:00 None +2020-02-03T00:00:00 None +2020-02-04T00:00:00 None +2020-02-05T00:00:00 None +2020-02-06T00:00:00 None +2020-02-07T00:00:00 None +2020-02-08T00:00:00 None +2020-02-09T00:00:00 None +2020-02-10T00:00:00 None +2020-02-11T00:00:00 None +2020-02-12T00:00:00 None +2020-02-13T00:00:00 None +2020-02-14T00:00:00 None +2020-02-15T00:00:00 None +2020-02-16T00:00:00 None +2020-02-17T00:00:00 None +2020-02-18T00:00:00 None +2020-02-19T00:00:00 None +2020-02-20T00:00:00 None +2020-02-21T00:00:00 None +2020-02-22T00:00:00 None +2020-02-23T00:00:00 None +2020-02-24T00:00:00 None +2020-02-25T00:00:00 None +2020-02-26T00:00:00 None +2020-02-27T00:00:00 None +2020-02-28T00:00:00 None +2020-02-29T00:00:00 None +2020-03-01T00:00:00 None +2020-03-02T00:00:00 None +2020-03-03T00:00:00 None +2020-03-04T00:00:00 None +2020-03-05T00:00:00 None +2020-03-06T00:00:00 None +2020-03-07T00:00:00 None +2020-03-08T00:00:00 None +2020-03-09T00:00:00 None +2020-03-10T00:00:00 None +2020-03-11T00:00:00 None +2020-03-12T00:00:00 None +2020-03-13T00:00:00 None +2020-03-14T00:00:00 None +2020-03-15T00:00:00 None +2020-03-16T00:00:00 None +2020-03-17T00:00:00 None +2020-03-18T00:00:00 None +2020-03-19T00:00:00 None +2020-03-20T00:00:00 None +2020-03-21T00:00:00 None +2020-03-22T00:00:00 None +2020-03-23T00:00:00 None +2020-03-24T00:00:00 None +2020-03-25T00:00:00 None +2020-03-26T00:00:00 None +2020-03-27T00:00:00 None +2020-03-28T00:00:00 None +2020-03-29T00:00:00 None +2020-03-30T00:00:00 None +2020-03-31T00:00:00 None +2020-04-01T00:00:00 None +2020-04-02T00:00:00 None +2020-04-03T00:00:00 None +2020-04-04T00:00:00 None +2020-04-05T00:00:00 None +2020-04-06T00:00:00 None +2020-04-07T00:00:00 None +2020-04-08T00:00:00 None +2020-04-09T00:00:00 None +2020-04-10T00:00:00 None +2020-04-11T00:00:00 None +2020-04-12T00:00:00 None +2020-04-13T00:00:00 None +2020-04-14T00:00:00 None +2020-04-15T00:00:00 None +2020-04-16T00:00:00 None +2020-04-17T00:00:00 None +2020-04-18T00:00:00 None +2020-04-19T00:00:00 None +2020-04-20T00:00:00 None +2020-04-21T00:00:00 None +2020-04-22T00:00:00 None +2020-04-23T00:00:00 None +2020-04-24T00:00:00 None +2020-04-25T00:00:00 None +2020-04-26T00:00:00 None +2020-04-27T00:00:00 None +2020-04-28T00:00:00 None +2020-04-29T00:00:00 None +2020-04-30T00:00:00 None +2020-05-01T00:00:00 None +2020-05-02T00:00:00 None +2020-05-03T00:00:00 None +2020-05-04T00:00:00 None +2020-05-05T00:00:00 None +2020-05-06T00:00:00 None +2020-05-07T00:00:00 None +2020-05-08T00:00:00 None +2020-05-09T00:00:00 None +2020-05-10T00:00:00 None +2020-05-11T00:00:00 None +2020-05-12T00:00:00 None +2020-05-13T00:00:00 None +2020-05-14T00:00:00 None +2020-05-15T00:00:00 None +2020-05-16T00:00:00 None +2020-05-17T00:00:00 None +2020-05-18T00:00:00 None +2020-05-19T00:00:00 None +2020-05-20T00:00:00 None +2020-05-21T00:00:00 None +2020-05-22T00:00:00 None +2020-05-23T00:00:00 None +2020-05-24T00:00:00 None +2020-05-25T00:00:00 None +2020-05-26T00:00:00 None +2020-05-27T00:00:00 None +2020-05-28T00:00:00 None +2020-05-29T00:00:00 None +2020-05-30T00:00:00 None +2020-05-31T00:00:00 None +2020-06-01T00:00:00 None +2020-06-02T00:00:00 None +2020-06-03T00:00:00 None +2020-06-04T00:00:00 None +2020-06-05T00:00:00 None +2020-06-06T00:00:00 None +2020-06-07T00:00:00 None +2020-06-08T00:00:00 None +2020-06-09T00:00:00 None +2020-06-10T00:00:00 None +2020-06-11T00:00:00 None +2020-06-12T00:00:00 None +2020-06-13T00:00:00 None +2020-06-14T00:00:00 None +2020-06-15T00:00:00 None +2020-06-16T00:00:00 None +2020-06-17T00:00:00 None +2020-06-18T00:00:00 None +2020-06-19T00:00:00 None +2020-06-20T00:00:00 None +2020-06-21T00:00:00 None +2020-06-22T00:00:00 None +2020-06-23T00:00:00 None +2020-06-24T00:00:00 None +2020-06-25T00:00:00 None +2020-06-26T00:00:00 None +2020-06-27T00:00:00 None +2020-06-28T00:00:00 None +2020-06-29T00:00:00 None +2020-06-30T00:00:00 None +2020-07-01T00:00:00 None +2020-07-02T00:00:00 None +2020-07-03T00:00:00 None +2020-07-04T00:00:00 None +2020-07-05T00:00:00 None +2020-07-06T00:00:00 None +2020-07-07T00:00:00 None +2020-07-08T00:00:00 None +2020-07-09T00:00:00 None +2020-07-10T00:00:00 None +2020-07-11T00:00:00 None +2020-07-12T00:00:00 None +2020-07-13T00:00:00 None +2020-07-14T00:00:00 None +2020-07-15T00:00:00 None +2020-07-16T00:00:00 None +2020-07-17T00:00:00 None +2020-07-18T00:00:00 None +2020-07-19T00:00:00 None +2020-07-20T00:00:00 None +2020-07-21T00:00:00 None +2020-07-22T00:00:00 None +2020-07-23T00:00:00 None +2020-07-24T00:00:00 None +2020-07-25T00:00:00 None +2020-07-26T00:00:00 None +2020-07-27T00:00:00 None +2020-07-28T00:00:00 None +2020-07-29T00:00:00 None +2020-07-30T00:00:00 None +2020-07-31T00:00:00 None +2020-08-01T00:00:00 None +2020-08-02T00:00:00 None +2020-08-03T00:00:00 None +2020-08-04T00:00:00 None +2020-08-05T00:00:00 None +2020-08-06T00:00:00 None +2020-08-07T00:00:00 None +2020-08-08T00:00:00 None +2020-08-09T00:00:00 None +2020-08-10T00:00:00 None +2020-08-11T00:00:00 None +2020-08-12T00:00:00 None +2020-08-13T00:00:00 None +2020-08-14T00:00:00 None +2020-08-15T00:00:00 None +2020-08-16T00:00:00 None +2020-08-17T00:00:00 None +2020-08-18T00:00:00 None +2020-08-19T00:00:00 None +2020-08-20T00:00:00 None +2020-08-21T00:00:00 None +2020-08-22T00:00:00 None +2020-08-23T00:00:00 None +2020-08-24T00:00:00 None +2020-08-25T00:00:00 None +2020-08-26T00:00:00 None +2020-08-27T00:00:00 None +2020-08-28T00:00:00 None +2020-08-29T00:00:00 None +2020-08-30T00:00:00 None +2020-08-31T00:00:00 None +2020-09-01T00:00:00 None +2020-09-02T00:00:00 None +2020-09-03T00:00:00 None +2020-09-04T00:00:00 None +2020-09-05T00:00:00 None +2020-09-06T00:00:00 None +2020-09-07T00:00:00 None +2020-09-08T00:00:00 None +2020-09-09T00:00:00 None +2020-09-10T00:00:00 None +2020-09-11T00:00:00 None +2020-09-12T00:00:00 None +2020-09-13T00:00:00 None +2020-09-14T00:00:00 None +2020-09-15T00:00:00 None +2020-09-16T00:00:00 None +2020-09-17T00:00:00 None +2020-09-18T00:00:00 None +2020-09-19T00:00:00 None +2020-09-20T00:00:00 None +2020-09-21T00:00:00 None +2020-09-22T00:00:00 None +2020-09-23T00:00:00 None +2020-09-24T00:00:00 None +2020-09-25T00:00:00 None +2020-09-26T00:00:00 None +2020-09-27T00:00:00 None +2020-09-28T00:00:00 None +2020-09-29T00:00:00 None +2020-09-30T00:00:00 None +2020-10-01T00:00:00 None +2020-10-02T00:00:00 None +2020-10-03T00:00:00 None +2020-10-04T00:00:00 None +2020-10-05T00:00:00 None +2020-10-06T00:00:00 None +2020-10-07T00:00:00 None +2020-10-08T00:00:00 None +2020-10-09T00:00:00 None +2020-10-10T00:00:00 None +2020-10-11T00:00:00 None +2020-10-12T00:00:00 None +2020-10-13T00:00:00 None +2020-10-14T00:00:00 None +2020-10-15T00:00:00 None +2020-10-16T00:00:00 None +2020-10-17T00:00:00 None +2020-10-18T00:00:00 None +2020-10-19T00:00:00 None +2020-10-20T00:00:00 None +2020-10-21T00:00:00 None +2020-10-22T00:00:00 None +2020-10-23T00:00:00 None +2020-10-24T00:00:00 None +2020-10-25T00:00:00 None +2020-10-26T00:00:00 None +2020-10-27T00:00:00 None +2020-10-28T00:00:00 None +2020-10-29T00:00:00 None +2020-10-30T00:00:00 None +2020-10-31T00:00:00 None +2020-11-01T00:00:00 None +2020-11-02T00:00:00 None +2020-11-03T00:00:00 None +2020-11-04T00:00:00 None +2020-11-05T00:00:00 None +2020-11-06T00:00:00 None +2020-11-07T00:00:00 None +2020-11-08T00:00:00 None +2020-11-09T00:00:00 None +2020-11-10T00:00:00 None +2020-11-11T00:00:00 None +2020-11-12T00:00:00 None +2020-11-13T00:00:00 None +2020-11-14T00:00:00 None +2020-11-15T00:00:00 None +2020-11-16T00:00:00 None +2020-11-17T00:00:00 None +2020-11-18T00:00:00 None +2020-11-19T00:00:00 None +2020-11-20T00:00:00 None +2020-11-21T00:00:00 None +2020-11-22T00:00:00 None +2020-11-23T00:00:00 None +2020-11-24T00:00:00 None +2020-11-25T00:00:00 None +2020-11-26T00:00:00 None +2020-11-27T00:00:00 None +2020-11-28T00:00:00 None +2020-11-29T00:00:00 None +2020-11-30T00:00:00 None +2020-12-01T00:00:00 None +2020-12-02T00:00:00 None +2020-12-03T00:00:00 None +2020-12-04T00:00:00 None +2020-12-05T00:00:00 None +2020-12-06T00:00:00 None +2020-12-07T00:00:00 None +2020-12-08T00:00:00 None +2020-12-09T00:00:00 None +2020-12-10T00:00:00 None +2020-12-11T00:00:00 None +2020-12-12T00:00:00 None +2020-12-13T00:00:00 None +2020-12-14T00:00:00 None +2020-12-15T00:00:00 None +2020-12-16T00:00:00 None +2020-12-17T00:00:00 None +2020-12-18T00:00:00 None +2020-12-19T00:00:00 None +2020-12-20T00:00:00 None +2020-12-21T00:00:00 None +2020-12-22T00:00:00 None +2020-12-23T00:00:00 None +2020-12-24T00:00:00 None +2020-12-25T00:00:00 None +2020-12-26T00:00:00 None +2020-12-27T00:00:00 None +2020-12-28T00:00:00 None +2020-12-29T00:00:00 None +2020-12-30T00:00:00 None +2020-12-31T00:00:00 None +2021-01-01T00:00:00 None +2021-01-02T00:00:00 None +2021-01-03T00:00:00 None +2021-01-04T00:00:00 None +2021-01-05T00:00:00 None +2021-01-06T00:00:00 None +2021-01-07T00:00:00 None +2021-01-08T00:00:00 None +2021-01-09T00:00:00 None +2021-01-10T00:00:00 None +2021-01-11T00:00:00 None +2021-01-12T00:00:00 None +2021-01-13T00:00:00 None +2021-01-14T00:00:00 None +2021-01-15T00:00:00 None +2021-01-16T00:00:00 None +2021-01-17T00:00:00 None +2021-01-18T00:00:00 None +2021-01-19T00:00:00 None +2021-01-20T00:00:00 None +2021-01-21T00:00:00 None +2021-01-22T00:00:00 None +2021-01-23T00:00:00 None +2021-01-24T00:00:00 None +2021-01-25T00:00:00 None +2021-01-26T00:00:00 None +2021-01-27T00:00:00 None +2021-01-28T00:00:00 None +2021-01-29T00:00:00 None +2021-01-30T00:00:00 None +2021-01-31T00:00:00 None +2021-02-01T00:00:00 None +2021-02-02T00:00:00 None +2021-02-03T00:00:00 None +2021-02-04T00:00:00 None +2021-02-05T00:00:00 None +2021-02-06T00:00:00 None +2021-02-07T00:00:00 None +2021-02-08T00:00:00 None +2021-02-09T00:00:00 None +2021-02-10T00:00:00 None +2021-02-11T00:00:00 None +2021-02-12T00:00:00 None +2021-02-13T00:00:00 None +2021-02-14T00:00:00 None +2021-02-15T00:00:00 None +2021-02-16T00:00:00 None +2021-02-17T00:00:00 None +2021-02-18T00:00:00 None +2021-02-19T00:00:00 None +2021-02-20T00:00:00 None +2021-02-21T00:00:00 None +2021-02-22T00:00:00 None +2021-02-23T00:00:00 None +2021-02-24T00:00:00 None +2021-02-25T00:00:00 None +2021-02-26T00:00:00 None +2021-02-27T00:00:00 None +2021-02-28T00:00:00 None +2021-03-01T00:00:00 None +2021-03-02T00:00:00 None +2021-03-03T00:00:00 None +2021-03-04T00:00:00 None +2021-03-05T00:00:00 None +2021-03-06T00:00:00 None +2021-03-07T00:00:00 None +2021-03-08T00:00:00 None +2021-03-09T00:00:00 None +2021-03-10T00:00:00 None +2021-03-11T00:00:00 None +2021-03-12T00:00:00 None +2021-03-13T00:00:00 None +2021-03-14T00:00:00 None +2021-03-15T00:00:00 None +2021-03-16T00:00:00 None +2021-03-17T00:00:00 None +2021-03-18T00:00:00 None +2021-03-19T00:00:00 None +2021-03-20T00:00:00 None +2021-03-21T00:00:00 None +2021-03-22T00:00:00 None +2021-03-23T00:00:00 None +2021-03-24T00:00:00 None +2021-03-25T00:00:00 None +2021-03-26T00:00:00 None +2021-03-27T00:00:00 None +2021-03-28T00:00:00 None +2021-03-29T00:00:00 None +2021-03-30T00:00:00 None +2021-03-31T00:00:00 None +2021-04-01T00:00:00 None +2021-04-02T00:00:00 None +2021-04-03T00:00:00 None +2021-04-04T00:00:00 None +2021-04-05T00:00:00 None +2021-04-06T00:00:00 None +2021-04-07T00:00:00 None +2021-04-08T00:00:00 None +2021-04-09T00:00:00 None +2021-04-10T00:00:00 None +2021-04-11T00:00:00 None +2021-04-12T00:00:00 None +2021-04-13T00:00:00 None +2021-04-14T00:00:00 None +2021-04-15T00:00:00 None +2021-04-16T00:00:00 None +2021-04-17T00:00:00 None +2021-04-18T00:00:00 None +2021-04-19T00:00:00 None +2021-04-20T00:00:00 None +2021-04-21T00:00:00 None +2021-04-22T00:00:00 None +2021-04-23T00:00:00 None +2021-04-24T00:00:00 None +2021-04-25T00:00:00 None +2021-04-26T00:00:00 None +2021-04-27T00:00:00 None +2021-04-28T00:00:00 None +2021-04-29T00:00:00 None +2021-04-30T00:00:00 None +2021-05-01T00:00:00 None +2021-05-02T00:00:00 None +2021-05-03T00:00:00 None +2021-05-04T00:00:00 None +2021-05-05T00:00:00 None +2021-05-06T00:00:00 None +2021-05-07T00:00:00 None +2021-05-08T00:00:00 None +2021-05-09T00:00:00 None +2021-05-10T00:00:00 None +2021-05-11T00:00:00 None +2021-05-12T00:00:00 None +2021-05-13T00:00:00 None +2021-05-14T00:00:00 None +2021-05-15T00:00:00 None +2021-05-16T00:00:00 None +2021-05-17T00:00:00 None +2021-05-18T00:00:00 None +2021-05-19T00:00:00 None +2021-05-20T00:00:00 None +2021-05-21T00:00:00 None +2021-05-22T00:00:00 None +2021-05-23T00:00:00 None +2021-05-24T00:00:00 None +2021-05-25T00:00:00 None +2021-05-26T00:00:00 None +2021-05-27T00:00:00 None +2021-05-28T00:00:00 None +2021-05-29T00:00:00 None +2021-05-30T00:00:00 None +2021-05-31T00:00:00 None +2021-06-01T00:00:00 None +2021-06-02T00:00:00 None +2021-06-03T00:00:00 None +2021-06-04T00:00:00 None +2021-06-05T00:00:00 None +2021-06-06T00:00:00 None +2021-06-07T00:00:00 None +2021-06-08T00:00:00 None +2021-06-09T00:00:00 None +2021-06-10T00:00:00 None +2021-06-11T00:00:00 None +2021-06-12T00:00:00 None +2021-06-13T00:00:00 None +2021-06-14T00:00:00 None +2021-06-15T00:00:00 None +2021-06-16T00:00:00 None +2021-06-17T00:00:00 None +2021-06-18T00:00:00 None +2021-06-19T00:00:00 None +2021-06-20T00:00:00 None +2021-06-21T00:00:00 None +2021-06-22T00:00:00 None +2021-06-23T00:00:00 None +2021-06-24T00:00:00 None +2021-06-25T00:00:00 None +2021-06-26T00:00:00 None +2021-06-27T00:00:00 None +2021-06-28T00:00:00 None +2021-06-29T00:00:00 None +2021-06-30T00:00:00 None +2021-07-01T00:00:00 None +2021-07-02T00:00:00 None +2021-07-03T00:00:00 None +2021-07-04T00:00:00 None +2021-07-05T00:00:00 None +2021-07-06T00:00:00 None +2021-07-07T00:00:00 None +2021-07-08T00:00:00 None +2021-07-09T00:00:00 None +2021-07-10T00:00:00 None +2021-07-11T00:00:00 None +2021-07-12T00:00:00 None +2021-07-13T00:00:00 None +2021-07-14T00:00:00 None +2021-07-15T00:00:00 None +2021-07-16T00:00:00 None +2021-07-17T00:00:00 None +2021-07-18T00:00:00 None +2021-07-19T00:00:00 None +2021-07-20T00:00:00 None +2021-07-21T00:00:00 None +2021-07-22T00:00:00 None +2021-07-23T00:00:00 None +2021-07-24T00:00:00 None +2021-07-25T00:00:00 None +2021-07-26T00:00:00 None +2021-07-27T00:00:00 None +2021-07-28T00:00:00 None +2021-07-29T00:00:00 None +2021-07-30T00:00:00 None +2021-07-31T00:00:00 None +2021-08-01T00:00:00 None +2021-08-02T00:00:00 None +2021-08-03T00:00:00 None +2021-08-04T00:00:00 None +2021-08-05T00:00:00 None +2021-08-06T00:00:00 None +2021-08-07T00:00:00 None +2021-08-08T00:00:00 None +2021-08-09T00:00:00 None +2021-08-10T00:00:00 None +2021-08-11T00:00:00 None +2021-08-12T00:00:00 None +2021-08-13T00:00:00 None +2021-08-14T00:00:00 None +2021-08-15T00:00:00 None +2021-08-16T00:00:00 None +2021-08-17T00:00:00 None +2021-08-18T00:00:00 None +2021-08-19T00:00:00 None +2021-08-20T00:00:00 None +2021-08-21T00:00:00 None +2021-08-22T00:00:00 None +2021-08-23T00:00:00 None +2021-08-24T00:00:00 None +2021-08-25T00:00:00 None +2021-08-26T00:00:00 None +2021-08-27T00:00:00 None +2021-08-28T00:00:00 None +2021-08-29T00:00:00 None +2021-08-30T00:00:00 None +2021-08-31T00:00:00 None +2021-09-01T00:00:00 None +2021-09-02T00:00:00 None +2021-09-03T00:00:00 None +2021-09-04T00:00:00 None +2021-09-05T00:00:00 None +2021-09-06T00:00:00 None +2021-09-07T00:00:00 None +2021-09-08T00:00:00 None +2021-09-09T00:00:00 None +2021-09-10T00:00:00 None +2021-09-11T00:00:00 None +2021-09-12T00:00:00 None +2021-09-13T00:00:00 None +2021-09-14T00:00:00 None +2021-09-15T00:00:00 None +2021-09-16T00:00:00 None +2021-09-17T00:00:00 None +2021-09-18T00:00:00 None +2021-09-19T00:00:00 None +2021-09-20T00:00:00 None +2021-09-21T00:00:00 None +2021-09-22T00:00:00 None +2021-09-23T00:00:00 None +2021-09-24T00:00:00 None +2021-09-25T00:00:00 None +2021-09-26T00:00:00 None +2021-09-27T00:00:00 None +2021-09-28T00:00:00 None +2021-09-29T00:00:00 None +2021-09-30T00:00:00 None +2021-10-01T00:00:00 None +2021-10-02T00:00:00 None +2021-10-03T00:00:00 None +2021-10-04T00:00:00 None +2021-10-05T00:00:00 None +2021-10-06T00:00:00 None +2021-10-07T00:00:00 None +2021-10-08T00:00:00 None +2021-10-09T00:00:00 None +2021-10-10T00:00:00 None +2021-10-11T00:00:00 None +2021-10-12T00:00:00 None +2021-10-13T00:00:00 None +2021-10-14T00:00:00 None +2021-10-15T00:00:00 None +2021-10-16T00:00:00 None +2021-10-17T00:00:00 None +2021-10-18T00:00:00 None +2021-10-19T00:00:00 None +2021-10-20T00:00:00 None +2021-10-21T00:00:00 None +2021-10-22T00:00:00 None +2021-10-23T00:00:00 None +2021-10-24T00:00:00 None +2021-10-25T00:00:00 None +2021-10-26T00:00:00 None +2021-10-27T00:00:00 None +2021-10-28T00:00:00 None +2021-10-29T00:00:00 None +2021-10-30T00:00:00 None +2021-10-31T00:00:00 None +2021-11-01T00:00:00 None +2021-11-02T00:00:00 None +2021-11-03T00:00:00 None +2021-11-04T00:00:00 None +2021-11-05T00:00:00 None +2021-11-06T00:00:00 None +2021-11-07T00:00:00 None +2021-11-08T00:00:00 None +2021-11-09T00:00:00 None +2021-11-10T00:00:00 None +2021-11-11T00:00:00 None +2021-11-12T00:00:00 None +2021-11-13T00:00:00 None +2021-11-14T00:00:00 None +2021-11-15T00:00:00 None +2021-11-16T00:00:00 None +2021-11-17T00:00:00 None +2021-11-18T00:00:00 None +2021-11-19T00:00:00 None +2021-11-20T00:00:00 None +2021-11-21T00:00:00 None +2021-11-22T00:00:00 None +2021-11-23T00:00:00 None +2021-11-24T00:00:00 None +2021-11-25T00:00:00 None 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 f1ab433c4e..545bb98eb4 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +373,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 ff83eff861..170b5bf10b 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 9fb6348b04..b79074f982 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,62 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -238,232 +270,264 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +620,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 35ec05e717..bc4c76ab9f 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.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_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_27.metric_time__day, subq_35.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_35.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -29,9 +29,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 ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -42,29 +42,29 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_27.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day GROUP BY metric_time__day - ) subq_31 + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY metric_time__day -) subq_32 +) subq_36 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 f906547d3e..96edca34db 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.metric_time__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS metric_time__month + , subq_5.ds__week + , 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__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 + 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 +379,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 61f5537d64..b3b28ec2e2 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' + -- Change Column Aliases 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 3b815691dd..f400517cac 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,70 @@ 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__week + , 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__martian_day + , subq_6.booking__ds__day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + 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__week + , 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__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 + 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 +381,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 e70deef36f..d108662a25 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' + -- Change Column Aliases 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 e83de302ce..6c870c0226 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS booking__ds__month + , subq_5.ds__week + , 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__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 + 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 +379,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 95caa9421e..9abe4c8cd0 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' + -- Change Column Aliases 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 a67b4d9f0b..a1c206a72e 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,70 @@ 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__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__day AS metric_time__day + , subq_5.ts__hour AS metric_time__hour + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +656,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 b069e9ae8e..16b7b528f7 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' + -- Change Column Aliases 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 d33848a09e..27a3341e0a 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,90 @@ 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__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__martian_day + , subq_8.metric_time__day + , subq_8.metric_time__week + FROM ( + -- Constrain Output with WHERE + SELECT + 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__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__week + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__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__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__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 +504,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 fc1d485a58..e1ed10542b 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' + -- Change Column Aliases 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 91d79f1546..642096615d 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 9cd507a222..ef18f2efa9 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 1a838af28e..a0292d4cea 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__month AS metric_time__month + , subq_4.ds__day + , subq_4.ds__week + , 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__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_4 + ) subq_5 GROUP BY metric_time__month - ) subq_4 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -229,5 +261,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 003a95adbf..03e91757ba 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' + -- Change Column Aliases + -- 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 329939234c..18a389f582 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +373,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 f402f4015f..f005994591 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 ff700c7982..d64c651b64 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,62 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -238,232 +270,264 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +620,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 352a3a6c85..b89168fc0c 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.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_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_27.metric_time__day, subq_35.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_35.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -29,9 +29,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 ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -42,29 +42,29 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_27.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 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 4370282ae7..d48cf9db24 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.metric_time__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS metric_time__month + , subq_5.ds__week + , 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__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 + 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 +379,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 2282acd201..1c41b2cb19 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' + -- Change Column Aliases 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 5356e33970..86e9b8c9ce 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,70 @@ 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__week + , 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__martian_day + , subq_6.booking__ds__day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + 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__week + , 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__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 + 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 +381,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 d9f5ff9262..8d1dab3990 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' + -- Change Column Aliases 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 73f9eb22d3..dd874f6c50 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS booking__ds__month + , subq_5.ds__week + , 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__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 + 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 +379,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 43db701576..9b671594f6 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' + -- Change Column Aliases 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 8346be424c..ce82121f18 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,70 @@ 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__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__day AS metric_time__day + , subq_5.ts__hour AS metric_time__hour + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +656,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 304c800e44..70b215bba9 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' + -- Change Column Aliases 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 f1d349a80d..d1c4005409 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,90 @@ 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__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__martian_day + , subq_8.metric_time__day + , subq_8.metric_time__week + FROM ( + -- Constrain Output with WHERE + SELECT + 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__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__week + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__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__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__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 +504,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 74c708c8ee..d1c5e27575 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' + -- Change Column Aliases 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 f2efd2d72d..cdc375cf9a 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 179c2b34b1..94ff4a4572 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 9d861ff6e5..b733b1e1e7 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__month AS metric_time__month + , subq_4.ds__day + , subq_4.ds__week + , 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__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_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 +261,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 dedc11ff7c..771c76f0a0 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' + -- Change Column Aliases + -- 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/DuckDB/test_cumulative_fill_nulls__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0.sql index bde8e65927..5a2f53708e 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0.sql @@ -4,19 +4,51 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day - , COALESCE(subq_9.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 + subq_10.metric_time__day + , COALESCE(subq_10.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_7.metric_time__day AS metric_time__day + subq_9.metric_time__day AS metric_time__day , subq_6.bookers AS bookers FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_8.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +373,5 @@ FROM ( subq_5.metric_time__day ) subq_6 ON - subq_7.metric_time__day = subq_6.metric_time__day -) subq_9 + subq_9.metric_time__day = subq_6.metric_time__day +) subq_10 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql index 1f7ba0288a..15065b1c75 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_fill_nulls__plan0_optimized.sql @@ -9,28 +9,28 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_18.ds AS metric_time__day - , subq_16.bookers AS bookers - FROM ***************************.mf_time_spine subq_18 + time_spine_src_28006.ds AS metric_time__day + , subq_17.bookers AS bookers + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__day'] -- Aggregate Measures SELECT - subq_13.ds AS metric_time__day + subq_14.ds AS metric_time__day , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers - FROM ***************************.mf_time_spine subq_13 + FROM ***************************.mf_time_spine subq_14 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_13.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_13.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.ds - INTERVAL 2 day ) GROUP BY - subq_13.ds - ) subq_16 + subq_14.ds + ) subq_17 ON - subq_18.ds = subq_16.metric_time__day -) subq_19 + time_spine_src_28006.ds = subq_17.metric_time__day +) subq_21 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql index b9c24f20ae..3f40143c3f 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -4,30 +4,62 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_16.metric_time__day + subq_18.metric_time__day , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_7.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , MAX(subq_15.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_8.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , MAX(subq_17.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 + subq_7.metric_time__day + , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -238,232 +270,264 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +620,18 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 - ) subq_9 + ) subq_9 + ) subq_10 ON - subq_10.metric_time__day - INTERVAL 14 day = subq_9.metric_time__day - ) subq_12 - ) subq_13 + subq_13.metric_time__day - INTERVAL 14 day = subq_10.metric_time__day + ) subq_14 + ) subq_15 GROUP BY - subq_13.metric_time__day - ) subq_14 - ) subq_15 + subq_15.metric_time__day + ) subq_16 + ) subq_17 ON - subq_7.metric_time__day = subq_15.metric_time__day + subq_8.metric_time__day = subq_17.metric_time__day GROUP BY - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) -) subq_16 + COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) +) subq_18 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql index 94a514eb38..303e4e7bae 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.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_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_27.metric_time__day, subq_35.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_35.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -29,9 +29,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 ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -42,29 +42,29 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_27.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql index cc87f575c1..ea9c07be1a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0.sql @@ -4,30 +4,68 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_9.metric_time__day + , subq_9.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS metric_time__day - , DATE_TRUNC('month', subq_6.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.metric_time__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS metric_time__month + , subq_5.ds__week + , 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__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 + 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 +379,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql index 83cb6095ed..988dd50080 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_18.metric_time__day AS metric_time__day + , subq_14.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Change Column Aliases SELECT ds AS metric_time__day , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - metric_time__month > '2020-01-01' - ) -) subq_14 + WHERE (metric_time__day <= '2020-01-02') AND (metric_time__month > '2020-01-01') +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -39,10 +37,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('month', ds) AS metric_time__month , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((metric_time__day >= '2020-01-02') AND (metric_time__day <= '2020-01-02')) AND (metric_time__month > '2020-01-01') GROUP BY metric_time__day -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql index 0c1226247f..8de3706f65 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0.sql @@ -4,31 +4,70 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.booking__ds__day - , subq_8.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_9.booking__ds__day + , subq_9.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( -- Join to Time Spine Dataset SELECT - subq_5.booking__ds__day AS booking__ds__day + subq_8.booking__ds__day AS booking__ds__day , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['booking__ds__day',] SELECT subq_7.booking__ds__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS booking__ds__day - , subq_6.ds AS metric_time__day - , DATE_TRUNC('month', subq_6.ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__week + , 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__martian_day + , subq_6.booking__ds__day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + 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__week + , 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__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 + 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 +381,5 @@ FROM ( subq_3.booking__ds__day ) subq_4 ON - subq_5.booking__ds__day = subq_4.booking__ds__day -) subq_8 + subq_8.booking__ds__day = subq_4.booking__ds__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql index bbcf6bed72..68fa98ca45 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__plan0_optimized.sql @@ -5,26 +5,24 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.booking__ds__day AS booking__ds__day - , subq_13.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_18.booking__ds__day AS booking__ds__day + , subq_14.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['booking__ds__day',] SELECT booking__ds__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Change Column Aliases SELECT ds AS booking__ds__day , ds AS metric_time__day , DATE_TRUNC('month', ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - booking__ds__month > '2020-01-01' - ) -) subq_14 + WHERE (metric_time__day <= '2020-01-02') AND (booking__ds__month > '2020-01-01') +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__ds__day'] @@ -41,10 +39,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((metric_time__day >= '2020-01-02') AND (metric_time__day <= '2020-01-02')) AND (booking__ds__month > '2020-01-01') GROUP BY booking__ds__day -) subq_13 +) subq_14 ON - subq_14.booking__ds__day = subq_13.booking__ds__day + subq_18.booking__ds__day = subq_14.booking__ds__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql index 6387b7c078..a40701c932 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0.sql @@ -4,30 +4,68 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_9.metric_time__day + , subq_9.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS metric_time__day - , DATE_TRUNC('month', subq_6.ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS booking__ds__month + , subq_5.ds__week + , 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__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 + 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 +379,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql index 56ac283876..34656b501d 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__plan0_optimized.sql @@ -5,25 +5,23 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.bookings AS bookings_join_to_time_spine_with_tiered_filters + subq_18.metric_time__day AS metric_time__day + , subq_14.bookings AS bookings_join_to_time_spine_with_tiered_filters FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Change Column Aliases SELECT ds AS metric_time__day , DATE_TRUNC('month', ds) AS booking__ds__month - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 - WHERE ( - metric_time__day <= '2020-01-02' - ) AND ( - booking__ds__month > '2020-01-01' - ) -) subq_14 + WHERE (metric_time__day <= '2020-01-02') AND (booking__ds__month > '2020-01-01') +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -39,10 +37,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((metric_time__day >= '2020-01-02') AND (metric_time__day <= '2020-01-02')) AND (booking__ds__month > '2020-01-01') GROUP BY metric_time__day -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql index 11529a53fb..62fddb8e7a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0.sql @@ -4,32 +4,70 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.archived_users AS archived_users_join_to_time_spine + subq_9.metric_time__day + , subq_9.archived_users AS archived_users_join_to_time_spine FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.archived_users AS archived_users FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Constrain Output with WHERE SELECT - DATE_TRUNC('day', subq_6.ts) AS metric_time__day - , subq_6.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_6 + subq_6.ts__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__day AS metric_time__day + , subq_5.ts__hour AS metric_time__hour + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +656,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql index 64e5073c79..40962ba36b 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__plan0_optimized.sql @@ -5,27 +5,25 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.archived_users AS archived_users_join_to_time_spine + subq_18.metric_time__day AS metric_time__day + , subq_14.archived_users AS archived_users_join_to_time_spine FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine_hour' + -- Change Column Aliases SELECT DATE_TRUNC('day', ts) AS metric_time__day , ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_15 + FROM ***************************.mf_time_spine_hour time_spine_src_28005 ) subq_16 - WHERE ( - metric_time__hour > '2020-01-01 00:09:00' - ) AND ( - metric_time__day = '2020-01-01' - ) + WHERE (metric_time__hour > '2020-01-01 00:09:00') AND (metric_time__day = '2020-01-01') GROUP BY metric_time__day -) subq_14 +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['archived_users', 'metric_time__day'] @@ -41,10 +39,10 @@ LEFT OUTER JOIN ( , DATE_TRUNC('day', archived_at) AS metric_time__day , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_10 + ) subq_11 WHERE (metric_time__hour > '2020-01-01 00:09:00') AND (metric_time__day = '2020-01-01') GROUP BY metric_time__day -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.metric_time__day diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql index 3661b1e49d..e5e3fae835 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0.sql @@ -4,32 +4,90 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , COALESCE(subq_10.bookings, 0) AS bookings_fill_nulls_with_0 + subq_12.metric_time__day + , COALESCE(subq_12.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_9.metric_time__day - , subq_9.bookings + subq_11.metric_time__day + , subq_11.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day + subq_10.metric_time__day AS metric_time__day , subq_5.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_8.metric_time__day + subq_9.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_7.ds AS metric_time__day - , DATE_TRUNC('week', subq_7.ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_7 - WHERE subq_7.ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_8 - WHERE metric_time__week > '2020-01-01' - ) subq_6 + subq_8.ds__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__martian_day + , subq_8.metric_time__day + , subq_8.metric_time__week + FROM ( + -- Constrain Output with WHERE + SELECT + 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__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__week + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__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__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__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 +504,7 @@ FROM ( subq_4.metric_time__day ) subq_5 ON - subq_6.metric_time__day = subq_5.metric_time__day - ) subq_9 - WHERE subq_9.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_10 + subq_10.metric_time__day = subq_5.metric_time__day + ) subq_11 + WHERE subq_11.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_12 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql index 289c4bd7a9..a29cff3999 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_filters__plan0_optimized.sql @@ -10,22 +10,28 @@ FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_17.metric_time__day AS metric_time__day - , subq_16.bookings AS bookings + subq_23.metric_time__day AS metric_time__day + , subq_18.bookings AS bookings FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Change Column Aliases SELECT ds AS metric_time__day , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_18 - WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_19 - WHERE metric_time__week > '2020-01-01' - ) subq_17 + FROM ***************************.mf_time_spine time_spine_src_28006 + ) subq_20 + WHERE ( + metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' + ) AND ( + metric_time__week > '2020-01-01' + ) + ) subq_23 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -43,12 +49,12 @@ FROM ( , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_13 + ) subq_15 WHERE metric_time__week > '2020-01-01' GROUP BY metric_time__day - ) subq_16 + ) subq_18 ON - subq_17.metric_time__day = subq_16.metric_time__day - WHERE subq_17.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_21 + subq_23.metric_time__day = subq_18.metric_time__day + WHERE subq_23.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_25 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql index 2aa9af4a15..fb928a6fe2 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0.sql @@ -4,19 +4,51 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 + subq_7.metric_time__day + , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,5 @@ FROM ( subq_2.metric_time__day ) subq_3 ON - subq_4.metric_time__day = subq_3.metric_time__day -) subq_6 + subq_6.metric_time__day = subq_3.metric_time__day +) subq_7 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql index 30f3bf383d..2f994958df 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql @@ -9,9 +9,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_12.ds AS metric_time__day - , subq_10.bookings AS bookings - FROM ***************************.mf_time_spine subq_12 + time_spine_src_28006.ds AS metric_time__day + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -25,10 +25,10 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__day - ) subq_10 + ) subq_11 ON - subq_12.ds = subq_10.metric_time__day -) subq_13 + time_spine_src_28006.ds = subq_11.metric_time__day +) subq_15 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql index 4263d4c10c..81c05fd111 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0.sql @@ -4,21 +4,53 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__month - , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 + subq_7.metric_time__month + , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__month AS metric_time__month + subq_6.metric_time__month AS metric_time__month , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__month',] SELECT - DATE_TRUNC('month', subq_5.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_5 + subq_5.metric_time__month + FROM ( + -- Change Column Aliases + SELECT + subq_4.ds__month AS metric_time__month + , subq_4.ds__day + , subq_4.ds__week + , 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__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_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 +261,5 @@ FROM ( subq_2.metric_time__month ) subq_3 ON - subq_4.metric_time__month = subq_3.metric_time__month -) subq_6 + subq_6.metric_time__month = subq_3.metric_time__month +) subq_7 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql index 2eaeedf472..87804af87f 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_month__plan0_optimized.sql @@ -9,16 +9,18 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_11.metric_time__month AS metric_time__month - , subq_10.bookings AS bookings + subq_14.metric_time__month AS metric_time__month + , subq_11.bookings AS bookings FROM ( -- Read From Time Spine 'mf_time_spine' + -- Change Column Aliases + -- 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 06958d27b0..a465512bc9 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +373,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 4881dd4607..40347e593c 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 d39655e2e2..effdeeaf46 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,62 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -238,232 +270,264 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +620,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 7caa70f512..9cb9ff0f3a 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.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_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_27.metric_time__day, subq_35.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_35.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -29,9 +29,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 ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -42,29 +42,29 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_27.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 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 6e0794f61d..613ff9b9f7 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.metric_time__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS metric_time__month + , subq_5.ds__week + , 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__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 + 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 +379,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 b4ad638e34..5d9d13b67b 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' + -- Change Column Aliases 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 529aff654a..a436bd0273 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,70 @@ 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__week + , 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__martian_day + , subq_6.booking__ds__day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + 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__week + , 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__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 + 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 +381,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 82aa6ba374..a271c0cf69 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' + -- Change Column Aliases 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 a08ad28212..caaba9e357 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS booking__ds__month + , subq_5.ds__week + , 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__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 + 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 +379,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 010c92bf29..3cc9d2f2fd 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' + -- Change Column Aliases 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 c304a7cbe8..83cc067fbb 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,70 @@ 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__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__day AS metric_time__day + , subq_5.ts__hour AS metric_time__hour + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +656,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 b305cd0dcf..e77eda9809 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' + -- Change Column Aliases 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 b6e2a39be8..1d71a3fa39 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,90 @@ 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__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__martian_day + , subq_8.metric_time__day + , subq_8.metric_time__week + FROM ( + -- Constrain Output with WHERE + SELECT + 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__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__week + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__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__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__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 +504,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 1aa6ec229b..2859b9d803 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' + -- Change Column Aliases 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 ee610ec2e3..523269744a 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 e5ad631c99..8ecb135bdb 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 14cd08fddf..1395a904cc 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__month AS metric_time__month + , subq_4.ds__day + , subq_4.ds__week + , 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__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_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 +261,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 7b2e9d7b67..f7e5b10e79 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' + -- Change Column Aliases + -- 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 f5848192ba..644c9d4b85 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +373,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 cff38d699e..2288080050 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 07a40daab5..863fd9c353 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,62 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -238,232 +270,264 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +620,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 f322daa090..a9f252ee25 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.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_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_27.metric_time__day, subq_35.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_35.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -29,9 +29,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 ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -42,29 +42,29 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_27.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 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 8774fd78d2..05d55b4642 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.metric_time__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS metric_time__month + , subq_5.ds__week + , 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__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 + 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 +379,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 0bf3b29076..904a8d9aa2 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' + -- Change Column Aliases 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 121b170ef1..8a919d4840 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,70 @@ 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__week + , 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__martian_day + , subq_6.booking__ds__day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + 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__week + , 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__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 + 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 +381,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 05d5c2c089..355d30bfbe 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' + -- Change Column Aliases 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 9285d0f173..570e63b540 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS booking__ds__month + , subq_5.ds__week + , 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__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 + 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 +379,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 13d7ad5eb7..cdb2ad6bc9 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' + -- Change Column Aliases 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 c49a223f64..3e6568ab61 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,70 @@ 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__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__day AS metric_time__day + , subq_5.ts__hour AS metric_time__hour + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +656,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 bf3835d2b1..911deb7948 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' + -- Change Column Aliases 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 9f9bde7590..960df99a07 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,90 @@ 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__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__martian_day + , subq_8.metric_time__day + , subq_8.metric_time__week + FROM ( + -- Constrain Output with WHERE + SELECT + 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__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__week + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__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__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__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 +504,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 9b9bd45b7f..5e5af3be24 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' + -- Change Column Aliases 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 7a79937faa..211ed339c6 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 98fb58c9c0..36fc75aa17 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 737a0e9338..bf636fce3c 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__month AS metric_time__month + , subq_4.ds__day + , subq_4.ds__week + , 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__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_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 +261,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 c66e456507..09c64b4a15 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' + -- Change Column Aliases + -- 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 b940e505ec..fd254f44a9 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +373,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 3fc6b83ac2..86bc959f0a 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 aacf956181..39a2f3d4a3 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,62 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -238,232 +270,264 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +620,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 09bcc2189c..2bf1ecb8ea 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.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_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_27.metric_time__day, subq_35.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_35.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -29,9 +29,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 ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -42,29 +42,29 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_27.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 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 e911843e27..6a1816a439 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.metric_time__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS metric_time__month + , subq_5.ds__week + , 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__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 + 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 +379,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 c3fbedd6ac..097fe9a592 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' + -- Change Column Aliases 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 dfe62f1d8a..f565ab4493 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,70 @@ 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__week + , 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__martian_day + , subq_6.booking__ds__day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + 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__week + , 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__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 + 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 +381,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 8e361ce9cb..5e8ed63504 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' + -- Change Column Aliases 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 79e86b2722..67b0945186 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS booking__ds__month + , subq_5.ds__week + , 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__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 + 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 +379,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 10f573e607..a670254cd1 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' + -- Change Column Aliases 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 e71ef86638..ccde941e08 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,70 @@ 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__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__day AS metric_time__day + , subq_5.ts__hour AS metric_time__hour + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +656,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 7cc83fd88c..e9e63dd182 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' + -- Change Column Aliases 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 8834fd78c4..ccb0af5b45 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,90 @@ 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__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__martian_day + , subq_8.metric_time__day + , subq_8.metric_time__week + FROM ( + -- Constrain Output with WHERE + SELECT + 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__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__week + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__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__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__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 +504,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 e943c194df..bce50988dd 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' + -- Change Column Aliases 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 e52e911b8a..9223480387 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 c1e9df5280..812595810a 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 996ab626df..f3f30f32cd 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__month AS metric_time__month + , subq_4.ds__day + , subq_4.ds__week + , 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__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_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 +261,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 6f302a497c..407e4b781f 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' + -- Change Column Aliases + -- 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 a96adb97ed..7ef865378e 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__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__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_7 + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -341,5 +373,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 4d68df91c8..a737bf8337 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 812cafa17d..759d7b037b 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,62 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -238,232 +270,264 @@ 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 ( + -- Change Column Aliases + SELECT + subq_11.ds__day AS metric_time__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__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_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 +620,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 02c664fe40..425dab581c 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 @@ -18,9 +18,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_31.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_31.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_27.metric_time__day, subq_35.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_35.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -29,9 +29,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 ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -42,29 +42,29 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_27.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_27 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('day', -14, subq_27.ds) = sma_28009_cte.metric_time__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - subq_27.ds - ) subq_31 + time_spine_src_28006.ds + ) subq_35 ON - subq_24.metric_time__day = subq_31.metric_time__day + subq_27.metric_time__day = subq_35.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_31.metric_time__day) -) subq_32 + COALESCE(subq_27.metric_time__day, subq_35.metric_time__day) +) subq_36 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 054ccef045..6275f67b93 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.metric_time__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS metric_time__month + , subq_5.ds__week + , 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__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 + 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 +379,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 3dc708c76e..bdd0136e12 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' + -- Change Column Aliases 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 9a183f5ef6..29385ce13a 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,70 @@ 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__week + , 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__martian_day + , subq_6.booking__ds__day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + 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__week + , 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__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 + 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 +381,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 30f440d3c7..6ee891e7b6 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' + -- Change Column Aliases 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 0e51c11f9f..a24e70996b 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,68 @@ 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__week + , 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__martian_day + , subq_6.metric_time__day + , subq_6.booking__ds__month + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.ds__month AS booking__ds__month + , subq_5.ds__week + , 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__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 + 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 +379,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 d99e51e0f0..cc17dc5fe8 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' + -- Change Column Aliases 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 0d0d478189..3d3988cf90 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,70 @@ 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__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__day AS metric_time__day + , subq_5.ts__hour AS metric_time__hour + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +656,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 3fc203f8d9..9225ef5cfc 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' + -- Change Column Aliases 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 3d8dc18017..9f9e4912a2 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,90 @@ 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__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__martian_day + , subq_8.metric_time__day + , subq_8.metric_time__week + FROM ( + -- Constrain Output with WHERE + SELECT + 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__martian_day + , subq_7.metric_time__day + , subq_7.metric_time__week + FROM ( + -- Change Column Aliases + SELECT + subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__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__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__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 +504,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 588e8f1d19..50e533170e 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' + -- Change Column Aliases 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 e2adfda223..6e481bf60d 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 1d62fa0a8b..64a16a3301 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 40c87b43fb..380273fae3 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,53 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__month AS metric_time__month + , subq_4.ds__day + , subq_4.ds__week + , 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__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_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 +261,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 bf59616d75..ea45baec08 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' + -- Change Column Aliases + -- 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 a505a20320..9ac345a079 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , 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_doy + , subq_7.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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 e5037b7d20..84f4512d66 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) AS metric_time__extract_dow - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) AS metric_time__extract_dow + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) = 1, 7, EXTRACT(dayofweek FROM subq_21.ds) - 1) AS metric_time__extract_dow + 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(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_21.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day GROUP BY metric_time__extract_dow - ) subq_25 + ) subq_27 ON - subq_18.metric_time__extract_dow = subq_25.metric_time__extract_dow + subq_19.metric_time__extract_dow = subq_27.metric_time__extract_dow GROUP BY metric_time__extract_dow -) subq_26 +) subq_28 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 6c1dc6ea59..195ab790d3 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 f1ce4bf137..9780279b2f 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 4e7932a2d4..f120ec0b82 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 96e2502fd9..afb11ecd8c 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 8a5c568458..cb23da2eca 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 5a9219415d..bedcf0999d 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 4f79f08a25..65225b5fb7 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 7997b120d8..9a21c21fee 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 b2926769d6..bc0e7ccf48 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,73 @@ 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__day + , subq_6.ts__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__hour AS metric_time__hour + , subq_5.ts__day + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +659,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 49cdb09ec4..008f6d913f 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' + -- Change Column Aliases + -- 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/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 78e5a822aa..9995adafe8 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , 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_doy + , subq_7.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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 b6a5cc8797..75e919a6af 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) AS metric_time__extract_dow - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) AS metric_time__extract_dow + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__extract_dow + EXTRACT(DAYOFWEEK_ISO FROM time_spine_src_28006.ds) AS metric_time__extract_dow , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - EXTRACT(DAYOFWEEK_ISO FROM subq_21.ds) - ) subq_25 + EXTRACT(DAYOFWEEK_ISO FROM time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__extract_dow = subq_25.metric_time__extract_dow + subq_19.metric_time__extract_dow = subq_27.metric_time__extract_dow GROUP BY - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) -) subq_26 + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) +) subq_28 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 6f285dc40f..1fe8a0a177 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 d0280d8ecd..5f3731d461 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 031c035f93..6d610b6529 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 95cde06772..cad51c6725 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 cea3e05ee3..664940b736 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 a2be431b34..45d51ea23b 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 be705a33d5..0501902b3c 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 33ac7b7e64..7c292f8d43 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 037d6a95e7..fcfed24283 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,73 @@ 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__day + , subq_6.ts__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__hour AS metric_time__hour + , subq_5.ts__day + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +659,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 dfce633cab..7bcc084193 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' + -- Change Column Aliases + -- 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/DuckDB/test_offset_window_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql index 95501d3106..81b8d3102d 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql @@ -4,14 +4,14 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_13.metric_time__extract_dow + subq_14.metric_time__extract_dow , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__extract_dow, subq_12.metric_time__extract_dow) AS metric_time__extract_dow + COALESCE(subq_4.metric_time__extract_dow, subq_13.metric_time__extract_dow) AS metric_time__extract_dow , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_13.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -230,18 +230,18 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__extract_dow - , subq_11.bookings AS bookings_2_weeks_ago + subq_12.metric_time__extract_dow + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_10.metric_time__extract_dow - , SUM(subq_10.bookings) AS bookings + subq_11.metric_time__extract_dow + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] SELECT - subq_9.metric_time__extract_dow - , subq_9.bookings + subq_10.metric_time__extract_dow + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT @@ -320,8 +320,8 @@ FROM ( , subq_6.metric_time__extract_month AS metric_time__extract_month , subq_6.metric_time__extract_day AS metric_time__extract_day , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__extract_dow AS metric_time__extract_dow + , subq_9.metric_time__day AS metric_time__day + , subq_9.metric_time__extract_dow AS metric_time__extract_dow , subq_6.listing AS listing , subq_6.guest AS guest , subq_6.host AS host @@ -344,12 +344,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , 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_doy + , subq_7.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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,15 @@ FROM ( ) subq_5 ) subq_6 ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + subq_9.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_10 + ) subq_11 GROUP BY - subq_10.metric_time__extract_dow - ) subq_11 - ) subq_12 + subq_11.metric_time__extract_dow + ) subq_12 + ) subq_13 ON - subq_4.metric_time__extract_dow = subq_12.metric_time__extract_dow + subq_4.metric_time__extract_dow = subq_13.metric_time__extract_dow GROUP BY - COALESCE(subq_4.metric_time__extract_dow, subq_12.metric_time__extract_dow) -) subq_13 + COALESCE(subq_4.metric_time__extract_dow, subq_13.metric_time__extract_dow) +) subq_14 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql index 8776484b8d..823a050c81 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0_optimized.sql @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) AS metric_time__extract_dow - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) AS metric_time__extract_dow + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__extract_dow + EXTRACT(isodow FROM time_spine_src_28006.ds) AS metric_time__extract_dow , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_21.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day GROUP BY - EXTRACT(isodow FROM subq_21.ds) - ) subq_25 + EXTRACT(isodow FROM time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__extract_dow = subq_25.metric_time__extract_dow + subq_19.metric_time__extract_dow = subq_27.metric_time__extract_dow GROUP BY - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) -) subq_26 + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) +) subq_28 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql index ea985a35da..834865d19b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0.sql @@ -4,19 +4,51 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users AS subdaily_join_to_time_spine_metric + subq_7.metric_time__hour + , subq_7.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__hour AS metric_time__hour + subq_6.metric_time__hour AS metric_time__hour , subq_3.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour',] SELECT - subq_5.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_5 - ) subq_4 + subq_5.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,5 @@ FROM ( subq_2.metric_time__hour ) subq_3 ON - subq_4.metric_time__hour = subq_3.metric_time__hour -) subq_6 + subq_6.metric_time__hour = subq_3.metric_time__hour +) subq_7 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql index cb9fd532c0..ea9ced6c5e 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_granularity_overrides_metric_default_granularity__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ts AS metric_time__hour - , subq_10.archived_users AS subdaily_join_to_time_spine_metric -FROM ***************************.mf_time_spine_hour subq_12 + time_spine_src_28005.ts AS metric_time__hour + , subq_11.archived_users AS subdaily_join_to_time_spine_metric +FROM ***************************.mf_time_spine_hour time_spine_src_28005 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -21,9 +21,9 @@ LEFT OUTER JOIN ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__hour -) subq_10 +) subq_11 ON - subq_12.ts = subq_10.metric_time__hour + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql index 8acb3f0a5d..0762a48bba 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0.sql @@ -4,19 +4,51 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users AS subdaily_join_to_time_spine_metric + subq_7.metric_time__hour + , subq_7.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__hour AS metric_time__hour + subq_6.metric_time__hour AS metric_time__hour , subq_3.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour',] SELECT - subq_5.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_5 - ) subq_4 + subq_5.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,5 @@ FROM ( subq_2.metric_time__hour ) subq_3 ON - subq_4.metric_time__hour = subq_3.metric_time__hour -) subq_6 + subq_6.metric_time__hour = subq_3.metric_time__hour +) subq_7 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql index de002a8a69..e30c1c2353 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_join_to_time_spine_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ts AS metric_time__hour - , subq_10.archived_users AS subdaily_join_to_time_spine_metric -FROM ***************************.mf_time_spine_hour subq_12 + time_spine_src_28005.ts AS metric_time__hour + , subq_11.archived_users AS subdaily_join_to_time_spine_metric +FROM ***************************.mf_time_spine_hour time_spine_src_28005 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -21,9 +21,9 @@ LEFT OUTER JOIN ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__hour -) subq_10 +) subq_11 ON - subq_12.ts = subq_10.metric_time__hour + time_spine_src_28005.ts = subq_11.metric_time__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql index 80237f2657..1b1c236304 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__hour + subq_8.metric_time__hour , archived_users AS subdaily_offset_grain_to_date_metric FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users + subq_7.metric_time__hour + , subq_7.archived_users FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__hour - , SUM(subq_5.archived_users) AS archived_users + subq_6.metric_time__hour + , SUM(subq_6.archived_users) AS archived_users FROM ( -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_4.metric_time__hour - , subq_4.archived_users + subq_5.metric_time__hour + , subq_5.archived_users FROM ( -- Join to Time Spine Dataset SELECT @@ -209,17 +209,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,10 @@ FROM ( ) subq_0 ) subq_1 ON - DATE_TRUNC('hour', subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + DATE_TRUNC('hour', subq_4.metric_time__hour) = subq_1.metric_time__hour + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__hour - ) subq_6 -) subq_7 + subq_6.metric_time__hour + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql index a13ee4f4ce..d1809f3035 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_to_grain_metric__plan0_optimized.sql @@ -12,9 +12,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ts AS metric_time__hour - , SUM(subq_9.archived_users) AS archived_users - FROM ***************************.mf_time_spine_hour subq_11 + time_spine_src_28005.ts AS metric_time__hour + , SUM(subq_10.archived_users) AS archived_users + FROM ***************************.mf_time_spine_hour time_spine_src_28005 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -22,9 +22,9 @@ FROM ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 ON - DATE_TRUNC('hour', subq_11.ts) = subq_9.metric_time__hour + DATE_TRUNC('hour', time_spine_src_28005.ts) = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql index 5caa97f29e..90671a2b07 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0.sql @@ -4,23 +4,23 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__hour + subq_8.metric_time__hour , archived_users AS subdaily_offset_window_metric FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users + subq_7.metric_time__hour + , subq_7.archived_users FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__hour - , SUM(subq_5.archived_users) AS archived_users + subq_6.metric_time__hour + , SUM(subq_6.archived_users) AS archived_users FROM ( -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_4.metric_time__hour - , subq_4.archived_users + subq_5.metric_time__hour + , subq_5.archived_users FROM ( -- Join to Time Spine Dataset SELECT @@ -209,17 +209,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,10 @@ FROM ( ) subq_0 ) subq_1 ON - subq_2.metric_time__hour - INTERVAL 1 hour = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + subq_4.metric_time__hour - INTERVAL 1 hour = subq_1.metric_time__hour + ) subq_5 + ) subq_6 GROUP BY - subq_5.metric_time__hour - ) subq_6 -) subq_7 + subq_6.metric_time__hour + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql index 78923e04e6..7d57881f43 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_offset_window_metric__plan0_optimized.sql @@ -12,9 +12,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.ts AS metric_time__hour - , SUM(subq_9.archived_users) AS archived_users - FROM ***************************.mf_time_spine_hour subq_11 + time_spine_src_28005.ts AS metric_time__hour + , SUM(subq_10.archived_users) AS archived_users + FROM ***************************.mf_time_spine_hour time_spine_src_28005 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -22,9 +22,9 @@ FROM ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_9 + ) subq_10 ON - subq_11.ts - INTERVAL 1 hour = subq_9.metric_time__hour + time_spine_src_28005.ts - INTERVAL 1 hour = subq_10.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + time_spine_src_28005.ts +) subq_17 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql index 73bd49f0a0..13336354fc 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0.sql @@ -4,25 +4,73 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__hour - , subq_8.archived_users AS subdaily_join_to_time_spine_metric + subq_10.metric_time__hour + , subq_10.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] SELECT - subq_7.metric_time__hour - , subq_7.archived_users + subq_9.metric_time__hour + , subq_9.archived_users FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__hour AS metric_time__hour + subq_8.metric_time__hour AS metric_time__hour , subq_4.archived_users AS archived_users FROM ( - -- Read From Time Spine 'mf_time_spine_hour' + -- Pass Only Elements: ['metric_time__hour',] SELECT - subq_6.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_6 - WHERE subq_6.ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' - ) subq_5 + subq_7.metric_time__hour + FROM ( + -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] + SELECT + subq_6.ts__day + , subq_6.ts__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__hour AS metric_time__hour + , subq_5.ts__day + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +659,7 @@ FROM ( subq_3.metric_time__hour ) subq_4 ON - subq_5.metric_time__hour = subq_4.metric_time__hour - ) subq_7 - WHERE subq_7.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' -) subq_8 + subq_8.metric_time__hour = subq_4.metric_time__hour + ) subq_9 + WHERE subq_9.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' +) subq_10 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql index c12dd7b5eb..ab05a47a39 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_with_metric__plan0_optimized.sql @@ -6,15 +6,18 @@ sql_engine: DuckDB -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] -- Compute Metrics via Expressions SELECT - subq_14.metric_time__hour AS metric_time__hour - , subq_13.archived_users AS subdaily_join_to_time_spine_metric + subq_19.metric_time__hour AS metric_time__hour + , subq_15.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Read From Time Spine 'mf_time_spine_hour' + -- Change Column Aliases + -- 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_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 6d998a8f59..7d63ccb295 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , 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_doy + , subq_7.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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 7f9cdb41c6..7daa131db6 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) AS metric_time__extract_dow - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) AS metric_time__extract_dow + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__extract_dow + EXTRACT(isodow FROM time_spine_src_28006.ds) AS metric_time__extract_dow , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_21.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day GROUP BY - EXTRACT(isodow FROM subq_21.ds) - ) subq_25 + EXTRACT(isodow FROM time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__extract_dow = subq_25.metric_time__extract_dow + subq_19.metric_time__extract_dow = subq_27.metric_time__extract_dow GROUP BY - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) -) subq_26 + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) +) subq_28 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 d066a3acb1..e8fa342bb7 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 07c19ae304..36cb00d7d9 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 4c9f57d85f..92045c6314 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 e4ddf574a2..86db1791da 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 01c5d362aa..831d260621 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 4ebee052c5..4393ab1af0 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 7423e9cecb..fbd844fe21 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 41dd8e3274..7975949ef7 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 e47857efa1..6f5bdbd17b 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,73 @@ 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__day + , subq_6.ts__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__hour AS metric_time__hour + , subq_5.ts__day + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +659,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 db2603787a..89f7ad0233 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' + -- Change Column Aliases + -- 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_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 ebc94261b2..dfbc4c831f 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , 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_doy + , subq_7.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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 f17e5751b5..6298887a21 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) AS metric_time__extract_dow - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) AS metric_time__extract_dow + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) = 0 THEN EXTRACT(dow FROM subq_21.ds) + 7 ELSE EXTRACT(dow FROM subq_21.ds) END AS metric_time__extract_dow + 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(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - CASE WHEN EXTRACT(dow FROM subq_21.ds) = 0 THEN EXTRACT(dow FROM subq_21.ds) + 7 ELSE EXTRACT(dow FROM subq_21.ds) END - ) subq_25 + 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_27 ON - subq_18.metric_time__extract_dow = subq_25.metric_time__extract_dow + subq_19.metric_time__extract_dow = subq_27.metric_time__extract_dow GROUP BY - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) -) subq_26 + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) +) subq_28 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 f0c40272ea..9583763f15 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 453237b4fd..6c82bf533d 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 54b24c63a0..87fbf902e8 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 0c0b432a25..602052f02d 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 1ffc9288b3..3920d61fc3 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 7b1ea188a2..8e7fb780f2 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 dec0c1f262..953f0abb48 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 eeb440b35e..94c485ec0d 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 720f5b5fcc..edee599bbf 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,73 @@ 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__day + , subq_6.ts__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__hour AS metric_time__hour + , subq_5.ts__day + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +659,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 ea228e49a5..0934765833 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' + -- Change Column Aliases + -- 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_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 4bf8aa2ad0..a6882fb7e4 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , 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_doy + , subq_7.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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 b13e774232..49beac3e1f 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) AS metric_time__extract_dow - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) AS metric_time__extract_dow + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__extract_dow + EXTRACT(dayofweekiso FROM time_spine_src_28006.ds) AS metric_time__extract_dow , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - EXTRACT(dayofweekiso FROM subq_21.ds) - ) subq_25 + EXTRACT(dayofweekiso FROM time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__extract_dow = subq_25.metric_time__extract_dow + subq_19.metric_time__extract_dow = subq_27.metric_time__extract_dow GROUP BY - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) -) subq_26 + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) +) subq_28 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 f49b63940c..7a07eac7ce 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 2eeeed0e10..bfd447c99b 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 886780f3c0..6a863b47d1 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 df5043613f..5364ec0572 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 40a67cce56..45031e3014 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 0ac8b25258..c6434d88be 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 eb88be7424..53d8149be8 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 0ee8b61dbc..ec5df2185b 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 e4a5141670..2c61e86422 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,73 @@ 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__day + , subq_6.ts__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__hour AS metric_time__hour + , subq_5.ts__day + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +659,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 bfbc3f9e21..f8a3211889 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' + -- Change Column Aliases + -- 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/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 86d96b5a51..76c944eca9 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,44 @@ 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 ( + -- Change Column Aliases + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__extract_dow AS metric_time__extract_dow + , 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_doy + , subq_7.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_7 + ) subq_8 + ) subq_9 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -546,15 +578,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 9ab8817df8..fc0bf13292 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 @@ -19,9 +19,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) AS metric_time__extract_dow - , MAX(subq_18.bookings) AS bookings - , MAX(subq_25.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) AS metric_time__extract_dow + , MAX(subq_19.bookings) AS bookings + , MAX(subq_27.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Read From CTE For node_id=sma_28009 -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] @@ -33,25 +33,25 @@ FROM ( FROM sma_28009_cte sma_28009_cte 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_21.ds) AS metric_time__extract_dow + EXTRACT(DAY_OF_WEEK FROM time_spine_src_28006.ds) AS metric_time__extract_dow , SUM(sma_28009_cte.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('day', -14, subq_21.ds) = sma_28009_cte.metric_time__day + DATE_ADD('day', -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day GROUP BY - EXTRACT(DAY_OF_WEEK FROM subq_21.ds) - ) subq_25 + EXTRACT(DAY_OF_WEEK FROM time_spine_src_28006.ds) + ) subq_27 ON - subq_18.metric_time__extract_dow = subq_25.metric_time__extract_dow + subq_19.metric_time__extract_dow = subq_27.metric_time__extract_dow GROUP BY - COALESCE(subq_18.metric_time__extract_dow, subq_25.metric_time__extract_dow) -) subq_26 + COALESCE(subq_19.metric_time__extract_dow, subq_27.metric_time__extract_dow) +) subq_28 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 e641672210..dd723817be 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 5a6cc12574..085d354e27 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 f0e67cd869..98021cd720 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ts__hour AS metric_time__hour + , subq_4.ts__day + , subq_4.ts__week + , subq_4.ts__month + , subq_4.ts__quarter + , subq_4.ts__year + , subq_4.ts__extract_year + , subq_4.ts__extract_quarter + , subq_4.ts__extract_month + , subq_4.ts__extract_day + , subq_4.ts__extract_dow + , subq_4.ts__extract_doy + 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 +442,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 ab20d4c194..1638287eec 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 d5e95786d7..d0df0642e9 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 6eca0ddc3f..b47f0d671e 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 fd5a04343d..b8f704c030 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,49 @@ 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 ( + -- Change Column Aliases + SELECT + subq_2.ts__hour AS metric_time__hour + , subq_2.ts__day + , subq_2.ts__week + , subq_2.ts__month + , subq_2.ts__quarter + , subq_2.ts__year + , subq_2.ts__extract_year + , subq_2.ts__extract_quarter + , subq_2.ts__extract_month + , subq_2.ts__extract_day + , subq_2.ts__extract_dow + , subq_2.ts__extract_doy + 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 +631,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 f51d27ebec..cdf9770ccc 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 aab4b84e77..7801dae2b0 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,73 @@ 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__day + , subq_6.ts__week + , subq_6.ts__month + , subq_6.ts__quarter + , subq_6.ts__year + , subq_6.ts__extract_year + , subq_6.ts__extract_quarter + , subq_6.ts__extract_month + , subq_6.ts__extract_day + , subq_6.ts__extract_dow + , subq_6.ts__extract_doy + , subq_6.metric_time__hour + FROM ( + -- Change Column Aliases + SELECT + subq_5.ts__hour AS metric_time__hour + , subq_5.ts__day + , subq_5.ts__week + , subq_5.ts__month + , subq_5.ts__quarter + , subq_5.ts__year + , subq_5.ts__extract_year + , subq_5.ts__extract_quarter + , subq_5.ts__extract_month + , subq_5.ts__extract_day + , subq_5.ts__extract_dow + , subq_5.ts__extract_doy + 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 +659,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 3b87095aeb..eb3a8574ee 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' + -- Change Column Aliases + -- 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_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml index b7e28d93bf..6733d8c187 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfp_0.xml @@ -128,6 +128,11 @@ docstring: + + + + + @@ -296,6 +301,11 @@ docstring: + + + + + @@ -303,7 +313,7 @@ docstring: - + @@ -361,9 +371,9 @@ docstring: - + - + @@ -380,6 +390,14 @@ docstring: + + + + + + + + @@ -396,7 +414,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml index a717daabf7..7f62d125b3 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_predicate_pushdown__dfpo_0.xml @@ -128,6 +128,11 @@ docstring: + + + + + @@ -135,7 +140,7 @@ docstring: - + @@ -151,9 +156,9 @@ docstring: - + - + @@ -212,7 +217,7 @@ docstring: - + @@ -295,6 +300,11 @@ docstring: + + + + + @@ -302,7 +312,7 @@ docstring: - + @@ -360,9 +370,9 @@ docstring: - + - + @@ -379,6 +389,14 @@ docstring: + + + + + + + + @@ -395,7 +413,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml index 83ae2a40c8..f68fcf1d8c 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfp_0.xml @@ -177,6 +177,11 @@ docstring: + + + + + @@ -396,6 +401,11 @@ docstring: + + + + + @@ -404,7 +414,7 @@ docstring: - + @@ -467,9 +477,9 @@ docstring: - + - + @@ -486,6 +496,14 @@ docstring: + + + + + + + + @@ -503,7 +521,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml index b14b72b938..fcff511062 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_fill_nulls_time_spine_metric_with_post_agg_join_predicate_pushdown__dfpo_0.xml @@ -177,6 +177,11 @@ docstring: + + + + + @@ -185,7 +190,7 @@ docstring: - + @@ -206,9 +211,9 @@ docstring: - + - + @@ -268,7 +273,7 @@ docstring: - + @@ -396,6 +401,11 @@ docstring: + + + + + @@ -404,7 +414,7 @@ docstring: - + @@ -467,9 +477,9 @@ docstring: - + - + @@ -486,6 +496,14 @@ docstring: + + + + + + + + @@ -503,7 +521,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml index f3563a7ffa..1ad26d419b 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfp_0.xml @@ -280,7 +280,7 @@ docstring: - + @@ -338,9 +338,9 @@ docstring: - + - + @@ -357,6 +357,14 @@ docstring: + + + + + + + + @@ -372,7 +380,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml index a0a27a1d88..bc47aa53c3 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_offset_metric_predicate_pushdown__dfpo_0.xml @@ -125,7 +125,7 @@ docstring: - + @@ -141,9 +141,9 @@ docstring: - + - + @@ -202,7 +202,7 @@ docstring: - + @@ -280,7 +280,7 @@ docstring: - + @@ -338,9 +338,9 @@ docstring: - + - + @@ -357,6 +357,14 @@ docstring: + + + + + + + + @@ -372,7 +380,7 @@ docstring: - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/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 e3720fbdc2..ed53a13d73 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,66 @@ 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 ( + -- Change Column Aliases + SELECT + subq_9.ds__day AS metric_time__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__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_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -596,451 +628,515 @@ 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 ( + -- Change Column Aliases + SELECT + subq_27.ds__day AS metric_time__day + , subq_27.ds__week + , subq_27.ds__month + , subq_27.ds__quarter + , subq_27.ds__year + , subq_27.ds__extract_year + , subq_27.ds__extract_quarter + , subq_27.ds__extract_month + , subq_27.ds__extract_day + , subq_27.ds__extract_dow + , subq_27.ds__extract_doy + , subq_27.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_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 ( + -- Change Column Aliases + SELECT + subq_16.ds__day AS metric_time__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.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_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 +1229,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 +1369,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 00bb832f0c..1664f5cfc0 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) AS metric_time__day - , COALESCE(subq_42.listing__country_latest, subq_56.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_56.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) AS metric_time__day + , COALESCE(subq_46.listing__country_latest, subq_62.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_62.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -47,10 +47,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'] @@ -71,16 +71,16 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_35 + ) 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 @@ -90,10 +90,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_54.ds AS metric_time__day - , subq_52.listing__country_latest AS listing__country_latest - , subq_52.bookings AS bookings - FROM ***************************.mf_time_spine subq_54 + time_spine_src_28006.ds AS metric_time__day + , subq_57.listing__country_latest AS listing__country_latest + , subq_57.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -106,43 +106,43 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_46.metric_time__day AS metric_time__day - , subq_46.booking__is_instant AS booking__is_instant - , subq_46.bookings AS bookings + , subq_51.metric_time__day AS metric_time__day + , subq_51.booking__is_instant AS booking__is_instant + , subq_51.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_45.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_45 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_45.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day - ) subq_46 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day + ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_46.listing = sma_28014_cte.listing - ) subq_49 + subq_51.listing = sma_28014_cte.listing + ) subq_54 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_52 + ) subq_57 ON - subq_54.ds = subq_52.metric_time__day - ) subq_55 - ) subq_56 + time_spine_src_28006.ds = subq_57.metric_time__day + ) subq_61 + ) subq_62 ON ( - subq_42.listing__country_latest = subq_56.listing__country_latest + subq_46.listing__country_latest = subq_62.listing__country_latest ) AND ( - subq_42.metric_time__day = subq_56.metric_time__day + subq_46.metric_time__day = subq_62.metric_time__day ) GROUP BY metric_time__day , listing__country_latest -) subq_57 +) subq_63 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 61b8e67dfe..8844c232f8 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_12.ds__day AS metric_time__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__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_12 + ) subq_13 + ) subq_14 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -1109,83 +1141,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 +1278,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 d80a13211b..c53bfc8011 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) AS metric_time__day - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) AS listing__country_latest - , MAX(subq_33.bookings) AS bookings - , MAX(subq_44.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) AS metric_time__day + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) AS listing__country_latest + , MAX(subq_34.bookings) AS bookings + , MAX(subq_46.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -59,12 +59,12 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_29 + ) 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'] @@ -78,39 +78,39 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_37.metric_time__day AS metric_time__day - , subq_37.booking__is_instant AS booking__is_instant - , subq_37.bookings AS bookings + , subq_39.metric_time__day AS metric_time__day + , subq_39.booking__is_instant AS booking__is_instant + , subq_39.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_36.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_36 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_SUB(CAST(subq_36.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day - ) subq_37 + DATE_SUB(CAST(time_spine_src_28006.ds AS DATETIME), INTERVAL 14 day) = sma_28009_cte.metric_time__day + ) subq_39 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_37.listing = sma_28014_cte.listing - ) subq_40 + subq_39.listing = sma_28014_cte.listing + ) subq_42 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_44 + ) subq_46 ON ( - subq_33.listing__country_latest = subq_44.listing__country_latest + subq_34.listing__country_latest = subq_46.listing__country_latest ) AND ( - subq_33.metric_time__day = subq_44.metric_time__day + subq_34.metric_time__day = subq_46.metric_time__day ) GROUP BY metric_time__day , listing__country_latest -) subq_45 +) subq_47 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 216c2ec201..660a39f42a 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -345,7 +377,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 2659e82a7b..9c9080de2a 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 f8a742f6d7..67040fc59d 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,66 @@ 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 ( + -- Change Column Aliases + SELECT + subq_9.ds__day AS metric_time__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__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_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -596,451 +628,515 @@ 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 ( + -- Change Column Aliases + SELECT + subq_27.ds__day AS metric_time__day + , subq_27.ds__week + , subq_27.ds__month + , subq_27.ds__quarter + , subq_27.ds__year + , subq_27.ds__extract_year + , subq_27.ds__extract_quarter + , subq_27.ds__extract_month + , subq_27.ds__extract_day + , subq_27.ds__extract_dow + , subq_27.ds__extract_doy + , subq_27.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_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 ( + -- Change Column Aliases + SELECT + subq_16.ds__day AS metric_time__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.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_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 +1229,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 +1369,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 a728cc0dac..d729f4a16a 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) AS metric_time__day - , COALESCE(subq_42.listing__country_latest, subq_56.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_56.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) AS metric_time__day + , COALESCE(subq_46.listing__country_latest, subq_62.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_62.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -47,10 +47,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'] @@ -71,16 +71,16 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_35 + ) 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 @@ -90,10 +90,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_54.ds AS metric_time__day - , subq_52.listing__country_latest AS listing__country_latest - , subq_52.bookings AS bookings - FROM ***************************.mf_time_spine subq_54 + time_spine_src_28006.ds AS metric_time__day + , subq_57.listing__country_latest AS listing__country_latest + , subq_57.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -106,43 +106,43 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_46.metric_time__day AS metric_time__day - , subq_46.booking__is_instant AS booking__is_instant - , subq_46.bookings AS bookings + , subq_51.metric_time__day AS metric_time__day + , subq_51.booking__is_instant AS booking__is_instant + , subq_51.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_45.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_45 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_45.ds) = sma_28009_cte.metric_time__day - ) subq_46 + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_46.listing = sma_28014_cte.listing - ) subq_49 + subq_51.listing = sma_28014_cte.listing + ) subq_54 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_52 + ) subq_57 ON - subq_54.ds = subq_52.metric_time__day - ) subq_55 - ) subq_56 + time_spine_src_28006.ds = subq_57.metric_time__day + ) subq_61 + ) subq_62 ON ( - subq_42.listing__country_latest = subq_56.listing__country_latest + subq_46.listing__country_latest = subq_62.listing__country_latest ) AND ( - subq_42.metric_time__day = subq_56.metric_time__day + subq_46.metric_time__day = subq_62.metric_time__day ) GROUP BY - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) - , COALESCE(subq_42.listing__country_latest, subq_56.listing__country_latest) -) subq_57 + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) + , COALESCE(subq_46.listing__country_latest, subq_62.listing__country_latest) +) subq_63 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 b13b34da59..8749ded6e7 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_12.ds__day AS metric_time__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__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_12 + ) subq_13 + ) subq_14 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -1109,83 +1141,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 +1278,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 c0ccdecfa6..8316523b11 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) AS metric_time__day - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) AS listing__country_latest - , MAX(subq_33.bookings) AS bookings - , MAX(subq_44.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) AS metric_time__day + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) AS listing__country_latest + , MAX(subq_34.bookings) AS bookings + , MAX(subq_46.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -59,12 +59,12 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_29 + ) 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'] @@ -78,39 +78,39 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_37.metric_time__day AS metric_time__day - , subq_37.booking__is_instant AS booking__is_instant - , subq_37.bookings AS bookings + , subq_39.metric_time__day AS metric_time__day + , subq_39.booking__is_instant AS booking__is_instant + , subq_39.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_36.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_36 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_36.ds) = sma_28009_cte.metric_time__day - ) subq_37 + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_39 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_37.listing = sma_28014_cte.listing - ) subq_40 + subq_39.listing = sma_28014_cte.listing + ) subq_42 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_44 + ) subq_46 ON ( - subq_33.listing__country_latest = subq_44.listing__country_latest + subq_34.listing__country_latest = subq_46.listing__country_latest ) AND ( - subq_33.metric_time__day = subq_44.metric_time__day + subq_34.metric_time__day = subq_46.metric_time__day ) GROUP BY - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) -) subq_45 + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) +) subq_47 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 95474dc021..3555ca0805 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -345,7 +377,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 7d1ca9d50a..241b0cd730 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/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql index 5b4e43f971..95a8d99490 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0.sql @@ -8,34 +8,66 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_29.metric_time__day - , subq_29.listing__country_latest + subq_32.metric_time__day + , subq_32.listing__country_latest , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0 FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_12.metric_time__day, subq_28.metric_time__day) AS metric_time__day - , COALESCE(subq_12.listing__country_latest, subq_28.listing__country_latest) AS listing__country_latest - , COALESCE(MAX(subq_12.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , COALESCE(MAX(subq_28.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_13.metric_time__day, subq_31.metric_time__day) AS metric_time__day + , COALESCE(subq_13.listing__country_latest, subq_31.listing__country_latest) AS listing__country_latest + , COALESCE(MAX(subq_13.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , COALESCE(MAX(subq_31.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day - , subq_11.listing__country_latest - , COALESCE(subq_11.bookings, 0) AS bookings_fill_nulls_with_0 + subq_12.metric_time__day + , subq_12.listing__country_latest + , COALESCE(subq_12.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_9.metric_time__day AS metric_time__day + subq_11.metric_time__day AS metric_time__day , subq_8.listing__country_latest AS listing__country_latest , subq_8.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_10.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_9.ds__day AS metric_time__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__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_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -596,451 +628,515 @@ 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 ( + -- Change Column Aliases + SELECT + subq_27.ds__day AS metric_time__day + , subq_27.ds__week + , subq_27.ds__month + , subq_27.ds__quarter + , subq_27.ds__year + , subq_27.ds__extract_year + , subq_27.ds__extract_quarter + , subq_27.ds__extract_month + , subq_27.ds__extract_day + , subq_27.ds__extract_dow + , subq_27.ds__extract_doy + , subq_27.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_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 ( + -- Change Column Aliases + SELECT + subq_16.ds__day AS metric_time__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.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_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 +1229,86 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 - ) subq_14 + ) subq_14 + ) subq_15 ON - subq_15.metric_time__day - INTERVAL 14 day = subq_14.metric_time__day - ) subq_17 + subq_18.metric_time__day - INTERVAL 14 day = subq_15.metric_time__day + ) subq_19 LEFT OUTER JOIN ( -- Pass Only Elements: ['country_latest', 'listing'] SELECT - subq_19.listing - , subq_19.country_latest + subq_21.listing + , subq_21.country_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_18.ds__day - , subq_18.ds__week - , subq_18.ds__month - , subq_18.ds__quarter - , subq_18.ds__year - , subq_18.ds__extract_year - , subq_18.ds__extract_quarter - , subq_18.ds__extract_month - , subq_18.ds__extract_day - , subq_18.ds__extract_dow - , subq_18.ds__extract_doy - , subq_18.created_at__day - , subq_18.created_at__week - , subq_18.created_at__month - , subq_18.created_at__quarter - , subq_18.created_at__year - , subq_18.created_at__extract_year - , subq_18.created_at__extract_quarter - , subq_18.created_at__extract_month - , subq_18.created_at__extract_day - , subq_18.created_at__extract_dow - , subq_18.created_at__extract_doy - , subq_18.listing__ds__day - , subq_18.listing__ds__week - , subq_18.listing__ds__month - , subq_18.listing__ds__quarter - , subq_18.listing__ds__year - , subq_18.listing__ds__extract_year - , subq_18.listing__ds__extract_quarter - , subq_18.listing__ds__extract_month - , subq_18.listing__ds__extract_day - , subq_18.listing__ds__extract_dow - , subq_18.listing__ds__extract_doy - , subq_18.listing__created_at__day - , subq_18.listing__created_at__week - , subq_18.listing__created_at__month - , subq_18.listing__created_at__quarter - , subq_18.listing__created_at__year - , subq_18.listing__created_at__extract_year - , subq_18.listing__created_at__extract_quarter - , subq_18.listing__created_at__extract_month - , subq_18.listing__created_at__extract_day - , subq_18.listing__created_at__extract_dow - , subq_18.listing__created_at__extract_doy - , subq_18.ds__day AS metric_time__day - , subq_18.ds__week AS metric_time__week - , subq_18.ds__month AS metric_time__month - , subq_18.ds__quarter AS metric_time__quarter - , subq_18.ds__year AS metric_time__year - , subq_18.ds__extract_year AS metric_time__extract_year - , subq_18.ds__extract_quarter AS metric_time__extract_quarter - , subq_18.ds__extract_month AS metric_time__extract_month - , subq_18.ds__extract_day AS metric_time__extract_day - , subq_18.ds__extract_dow AS metric_time__extract_dow - , subq_18.ds__extract_doy AS metric_time__extract_doy - , subq_18.listing - , subq_18.user - , subq_18.listing__user - , subq_18.country_latest - , subq_18.is_lux_latest - , subq_18.capacity_latest - , subq_18.listing__country_latest - , subq_18.listing__is_lux_latest - , subq_18.listing__capacity_latest - , subq_18.listings - , subq_18.largest_listing - , subq_18.smallest_listing + subq_20.ds__day + , subq_20.ds__week + , subq_20.ds__month + , subq_20.ds__quarter + , subq_20.ds__year + , subq_20.ds__extract_year + , subq_20.ds__extract_quarter + , subq_20.ds__extract_month + , subq_20.ds__extract_day + , subq_20.ds__extract_dow + , subq_20.ds__extract_doy + , subq_20.created_at__day + , subq_20.created_at__week + , subq_20.created_at__month + , subq_20.created_at__quarter + , subq_20.created_at__year + , subq_20.created_at__extract_year + , subq_20.created_at__extract_quarter + , subq_20.created_at__extract_month + , subq_20.created_at__extract_day + , subq_20.created_at__extract_dow + , subq_20.created_at__extract_doy + , subq_20.listing__ds__day + , subq_20.listing__ds__week + , subq_20.listing__ds__month + , subq_20.listing__ds__quarter + , subq_20.listing__ds__year + , subq_20.listing__ds__extract_year + , subq_20.listing__ds__extract_quarter + , subq_20.listing__ds__extract_month + , subq_20.listing__ds__extract_day + , subq_20.listing__ds__extract_dow + , subq_20.listing__ds__extract_doy + , subq_20.listing__created_at__day + , subq_20.listing__created_at__week + , subq_20.listing__created_at__month + , subq_20.listing__created_at__quarter + , subq_20.listing__created_at__year + , subq_20.listing__created_at__extract_year + , subq_20.listing__created_at__extract_quarter + , subq_20.listing__created_at__extract_month + , subq_20.listing__created_at__extract_day + , subq_20.listing__created_at__extract_dow + , subq_20.listing__created_at__extract_doy + , subq_20.ds__day AS metric_time__day + , subq_20.ds__week AS metric_time__week + , subq_20.ds__month AS metric_time__month + , subq_20.ds__quarter AS metric_time__quarter + , subq_20.ds__year AS metric_time__year + , subq_20.ds__extract_year AS metric_time__extract_year + , subq_20.ds__extract_quarter AS metric_time__extract_quarter + , subq_20.ds__extract_month AS metric_time__extract_month + , subq_20.ds__extract_day AS metric_time__extract_day + , subq_20.ds__extract_dow AS metric_time__extract_dow + , subq_20.ds__extract_doy AS metric_time__extract_doy + , subq_20.listing + , subq_20.user + , subq_20.listing__user + , subq_20.country_latest + , subq_20.is_lux_latest + , subq_20.capacity_latest + , subq_20.listing__country_latest + , subq_20.listing__is_lux_latest + , subq_20.listing__capacity_latest + , subq_20.listings + , subq_20.largest_listing + , subq_20.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -1273,30 +1369,30 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_18 - ) subq_19 - ) subq_20 + ) subq_20 + ) subq_21 + ) subq_22 ON - subq_17.listing = subq_20.listing - ) subq_21 + subq_19.listing = subq_22.listing + ) subq_23 WHERE booking__is_instant - ) subq_22 - ) subq_23 + ) subq_24 + ) subq_25 GROUP BY - subq_23.metric_time__day - , subq_23.listing__country_latest - ) subq_24 + subq_25.metric_time__day + , subq_25.listing__country_latest + ) subq_26 ON - subq_25.metric_time__day = subq_24.metric_time__day - ) subq_27 - ) subq_28 + subq_29.metric_time__day = subq_26.metric_time__day + ) subq_30 + ) subq_31 ON ( - subq_12.listing__country_latest = subq_28.listing__country_latest + subq_13.listing__country_latest = subq_31.listing__country_latest ) AND ( - subq_12.metric_time__day = subq_28.metric_time__day + subq_13.metric_time__day = subq_31.metric_time__day ) GROUP BY - COALESCE(subq_12.metric_time__day, subq_28.metric_time__day) - , COALESCE(subq_12.listing__country_latest, subq_28.listing__country_latest) -) subq_29 + COALESCE(subq_13.metric_time__day, subq_31.metric_time__day) + , COALESCE(subq_13.listing__country_latest, subq_31.listing__country_latest) +) subq_32 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql index af754501ef..6e7efd837d 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_fill_nulls_time_spine_metric_predicate_pushdown__plan0_optimized.sql @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) AS metric_time__day - , COALESCE(subq_42.listing__country_latest, subq_56.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_56.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) AS metric_time__day + , COALESCE(subq_46.listing__country_latest, subq_62.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_62.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -47,10 +47,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'] @@ -71,16 +71,16 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_35 + ) 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 @@ -90,10 +90,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_54.ds AS metric_time__day - , subq_52.listing__country_latest AS listing__country_latest - , subq_52.bookings AS bookings - FROM ***************************.mf_time_spine subq_54 + time_spine_src_28006.ds AS metric_time__day + , subq_57.listing__country_latest AS listing__country_latest + , subq_57.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -106,43 +106,43 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_46.metric_time__day AS metric_time__day - , subq_46.booking__is_instant AS booking__is_instant - , subq_46.bookings AS bookings + , subq_51.metric_time__day AS metric_time__day + , subq_51.booking__is_instant AS booking__is_instant + , subq_51.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_45.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_45 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_45.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day - ) subq_46 + time_spine_src_28006.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day + ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_46.listing = sma_28014_cte.listing - ) subq_49 + subq_51.listing = sma_28014_cte.listing + ) subq_54 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_52 + ) subq_57 ON - subq_54.ds = subq_52.metric_time__day - ) subq_55 - ) subq_56 + time_spine_src_28006.ds = subq_57.metric_time__day + ) subq_61 + ) subq_62 ON ( - subq_42.listing__country_latest = subq_56.listing__country_latest + subq_46.listing__country_latest = subq_62.listing__country_latest ) AND ( - subq_42.metric_time__day = subq_56.metric_time__day + subq_46.metric_time__day = subq_62.metric_time__day ) GROUP BY - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) - , COALESCE(subq_42.listing__country_latest, subq_56.listing__country_latest) -) subq_57 + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) + , COALESCE(subq_46.listing__country_latest, subq_62.listing__country_latest) +) subq_63 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql index aee6eca8dc..dff46df643 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0.sql @@ -8,16 +8,16 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_23.metric_time__day - , subq_23.listing__country_latest + subq_24.metric_time__day + , subq_24.listing__country_latest , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_9.metric_time__day, subq_22.metric_time__day) AS metric_time__day - , COALESCE(subq_9.listing__country_latest, subq_22.listing__country_latest) AS listing__country_latest + COALESCE(subq_9.metric_time__day, subq_23.metric_time__day) AS metric_time__day + , COALESCE(subq_9.listing__country_latest, subq_23.listing__country_latest) AS listing__country_latest , MAX(subq_9.bookings) AS bookings - , MAX(subq_22.bookings_2_weeks_ago) AS bookings_2_weeks_ago + , MAX(subq_23.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -587,225 +587,225 @@ FROM ( FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_21.metric_time__day - , subq_21.listing__country_latest - , subq_21.bookings AS bookings_2_weeks_ago + subq_22.metric_time__day + , subq_22.listing__country_latest + , subq_22.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_20.metric_time__day - , subq_20.listing__country_latest - , SUM(subq_20.bookings) AS bookings + subq_21.metric_time__day + , subq_21.listing__country_latest + , SUM(subq_21.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] SELECT - subq_19.metric_time__day - , subq_19.listing__country_latest - , subq_19.bookings + subq_20.metric_time__day + , subq_20.listing__country_latest + , subq_20.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_18.metric_time__day - , subq_18.ds__day - , subq_18.ds__week - , subq_18.ds__month - , subq_18.ds__quarter - , subq_18.ds__year - , subq_18.ds__extract_year - , subq_18.ds__extract_quarter - , subq_18.ds__extract_month - , subq_18.ds__extract_day - , subq_18.ds__extract_dow - , subq_18.ds__extract_doy - , subq_18.ds_partitioned__day - , subq_18.ds_partitioned__week - , subq_18.ds_partitioned__month - , subq_18.ds_partitioned__quarter - , subq_18.ds_partitioned__year - , subq_18.ds_partitioned__extract_year - , subq_18.ds_partitioned__extract_quarter - , subq_18.ds_partitioned__extract_month - , subq_18.ds_partitioned__extract_day - , subq_18.ds_partitioned__extract_dow - , subq_18.ds_partitioned__extract_doy - , subq_18.paid_at__day - , subq_18.paid_at__week - , subq_18.paid_at__month - , subq_18.paid_at__quarter - , subq_18.paid_at__year - , subq_18.paid_at__extract_year - , subq_18.paid_at__extract_quarter - , subq_18.paid_at__extract_month - , subq_18.paid_at__extract_day - , subq_18.paid_at__extract_dow - , subq_18.paid_at__extract_doy - , subq_18.booking__ds__day - , subq_18.booking__ds__week - , subq_18.booking__ds__month - , subq_18.booking__ds__quarter - , subq_18.booking__ds__year - , subq_18.booking__ds__extract_year - , subq_18.booking__ds__extract_quarter - , subq_18.booking__ds__extract_month - , subq_18.booking__ds__extract_day - , subq_18.booking__ds__extract_dow - , subq_18.booking__ds__extract_doy - , subq_18.booking__ds_partitioned__day - , subq_18.booking__ds_partitioned__week - , subq_18.booking__ds_partitioned__month - , subq_18.booking__ds_partitioned__quarter - , subq_18.booking__ds_partitioned__year - , subq_18.booking__ds_partitioned__extract_year - , subq_18.booking__ds_partitioned__extract_quarter - , subq_18.booking__ds_partitioned__extract_month - , subq_18.booking__ds_partitioned__extract_day - , subq_18.booking__ds_partitioned__extract_dow - , subq_18.booking__ds_partitioned__extract_doy - , subq_18.booking__paid_at__day - , subq_18.booking__paid_at__week - , subq_18.booking__paid_at__month - , subq_18.booking__paid_at__quarter - , subq_18.booking__paid_at__year - , subq_18.booking__paid_at__extract_year - , subq_18.booking__paid_at__extract_quarter - , subq_18.booking__paid_at__extract_month - , subq_18.booking__paid_at__extract_day - , subq_18.booking__paid_at__extract_dow - , subq_18.booking__paid_at__extract_doy - , subq_18.metric_time__week - , subq_18.metric_time__month - , subq_18.metric_time__quarter - , subq_18.metric_time__year - , subq_18.metric_time__extract_year - , subq_18.metric_time__extract_quarter - , subq_18.metric_time__extract_month - , subq_18.metric_time__extract_day - , subq_18.metric_time__extract_dow - , subq_18.metric_time__extract_doy - , subq_18.listing - , subq_18.guest - , subq_18.host - , subq_18.booking__listing - , subq_18.booking__guest - , subq_18.booking__host - , subq_18.is_instant - , subq_18.booking__is_instant - , subq_18.listing__country_latest - , subq_18.bookings - , subq_18.instant_bookings - , subq_18.booking_value - , subq_18.max_booking_value - , subq_18.min_booking_value - , subq_18.bookers - , subq_18.average_booking_value - , subq_18.referred_bookings - , subq_18.median_booking_value - , subq_18.booking_value_p99 - , subq_18.discrete_booking_value_p99 - , subq_18.approximate_continuous_booking_value_p99 - , subq_18.approximate_discrete_booking_value_p99 + subq_19.ds__day + , subq_19.ds__week + , subq_19.ds__month + , subq_19.ds__quarter + , subq_19.ds__year + , subq_19.ds__extract_year + , subq_19.ds__extract_quarter + , subq_19.ds__extract_month + , subq_19.ds__extract_day + , subq_19.ds__extract_dow + , subq_19.ds__extract_doy + , subq_19.ds_partitioned__day + , subq_19.ds_partitioned__week + , subq_19.ds_partitioned__month + , subq_19.ds_partitioned__quarter + , subq_19.ds_partitioned__year + , subq_19.ds_partitioned__extract_year + , subq_19.ds_partitioned__extract_quarter + , subq_19.ds_partitioned__extract_month + , subq_19.ds_partitioned__extract_day + , subq_19.ds_partitioned__extract_dow + , subq_19.ds_partitioned__extract_doy + , subq_19.paid_at__day + , subq_19.paid_at__week + , subq_19.paid_at__month + , subq_19.paid_at__quarter + , subq_19.paid_at__year + , subq_19.paid_at__extract_year + , subq_19.paid_at__extract_quarter + , subq_19.paid_at__extract_month + , subq_19.paid_at__extract_day + , subq_19.paid_at__extract_dow + , subq_19.paid_at__extract_doy + , subq_19.booking__ds__day + , subq_19.booking__ds__week + , subq_19.booking__ds__month + , subq_19.booking__ds__quarter + , subq_19.booking__ds__year + , subq_19.booking__ds__extract_year + , subq_19.booking__ds__extract_quarter + , subq_19.booking__ds__extract_month + , subq_19.booking__ds__extract_day + , subq_19.booking__ds__extract_dow + , subq_19.booking__ds__extract_doy + , subq_19.booking__ds_partitioned__day + , subq_19.booking__ds_partitioned__week + , subq_19.booking__ds_partitioned__month + , subq_19.booking__ds_partitioned__quarter + , subq_19.booking__ds_partitioned__year + , subq_19.booking__ds_partitioned__extract_year + , subq_19.booking__ds_partitioned__extract_quarter + , subq_19.booking__ds_partitioned__extract_month + , subq_19.booking__ds_partitioned__extract_day + , subq_19.booking__ds_partitioned__extract_dow + , subq_19.booking__ds_partitioned__extract_doy + , subq_19.booking__paid_at__day + , subq_19.booking__paid_at__week + , subq_19.booking__paid_at__month + , subq_19.booking__paid_at__quarter + , subq_19.booking__paid_at__year + , subq_19.booking__paid_at__extract_year + , subq_19.booking__paid_at__extract_quarter + , subq_19.booking__paid_at__extract_month + , subq_19.booking__paid_at__extract_day + , subq_19.booking__paid_at__extract_dow + , subq_19.booking__paid_at__extract_doy + , subq_19.metric_time__week + , subq_19.metric_time__month + , subq_19.metric_time__quarter + , subq_19.metric_time__year + , subq_19.metric_time__extract_year + , subq_19.metric_time__extract_quarter + , subq_19.metric_time__extract_month + , subq_19.metric_time__extract_day + , subq_19.metric_time__extract_dow + , subq_19.metric_time__extract_doy + , subq_19.metric_time__day + , subq_19.listing + , subq_19.guest + , subq_19.host + , subq_19.booking__listing + , subq_19.booking__guest + , subq_19.booking__host + , subq_19.is_instant + , subq_19.booking__is_instant + , subq_19.listing__country_latest + , subq_19.bookings + , subq_19.instant_bookings + , subq_19.booking_value + , subq_19.max_booking_value + , subq_19.min_booking_value + , subq_19.bookers + , subq_19.average_booking_value + , subq_19.referred_bookings + , subq_19.median_booking_value + , subq_19.booking_value_p99 + , subq_19.discrete_booking_value_p99 + , subq_19.approximate_continuous_booking_value_p99 + , subq_19.approximate_discrete_booking_value_p99 FROM ( -- Join Standard Outputs SELECT - subq_17.country_latest AS listing__country_latest - , subq_14.metric_time__day AS metric_time__day - , subq_14.ds__day AS ds__day - , subq_14.ds__week AS ds__week - , subq_14.ds__month AS ds__month - , subq_14.ds__quarter AS ds__quarter - , subq_14.ds__year AS ds__year - , subq_14.ds__extract_year AS ds__extract_year - , subq_14.ds__extract_quarter AS ds__extract_quarter - , subq_14.ds__extract_month AS ds__extract_month - , subq_14.ds__extract_day AS ds__extract_day - , subq_14.ds__extract_dow AS ds__extract_dow - , subq_14.ds__extract_doy AS ds__extract_doy - , subq_14.ds_partitioned__day AS ds_partitioned__day - , subq_14.ds_partitioned__week AS ds_partitioned__week - , subq_14.ds_partitioned__month AS ds_partitioned__month - , subq_14.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_14.ds_partitioned__year AS ds_partitioned__year - , subq_14.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_14.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_14.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_14.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_14.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_14.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_14.paid_at__day AS paid_at__day - , subq_14.paid_at__week AS paid_at__week - , subq_14.paid_at__month AS paid_at__month - , subq_14.paid_at__quarter AS paid_at__quarter - , subq_14.paid_at__year AS paid_at__year - , subq_14.paid_at__extract_year AS paid_at__extract_year - , subq_14.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_14.paid_at__extract_month AS paid_at__extract_month - , subq_14.paid_at__extract_day AS paid_at__extract_day - , subq_14.paid_at__extract_dow AS paid_at__extract_dow - , subq_14.paid_at__extract_doy AS paid_at__extract_doy - , subq_14.booking__ds__day AS booking__ds__day - , subq_14.booking__ds__week AS booking__ds__week - , subq_14.booking__ds__month AS booking__ds__month - , subq_14.booking__ds__quarter AS booking__ds__quarter - , subq_14.booking__ds__year AS booking__ds__year - , subq_14.booking__ds__extract_year AS booking__ds__extract_year - , subq_14.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_14.booking__ds__extract_month AS booking__ds__extract_month - , subq_14.booking__ds__extract_day AS booking__ds__extract_day - , subq_14.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_14.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_14.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_14.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_14.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_14.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_14.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_14.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_14.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_14.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_14.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_14.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_14.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_14.booking__paid_at__day AS booking__paid_at__day - , subq_14.booking__paid_at__week AS booking__paid_at__week - , subq_14.booking__paid_at__month AS booking__paid_at__month - , subq_14.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_14.booking__paid_at__year AS booking__paid_at__year - , subq_14.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_14.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_14.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_14.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_14.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_14.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_14.metric_time__week AS metric_time__week - , subq_14.metric_time__month AS metric_time__month - , subq_14.metric_time__quarter AS metric_time__quarter - , subq_14.metric_time__year AS metric_time__year - , subq_14.metric_time__extract_year AS metric_time__extract_year - , subq_14.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_14.metric_time__extract_month AS metric_time__extract_month - , subq_14.metric_time__extract_day AS metric_time__extract_day - , subq_14.metric_time__extract_dow AS metric_time__extract_dow - , subq_14.metric_time__extract_doy AS metric_time__extract_doy - , subq_14.listing AS listing - , subq_14.guest AS guest - , subq_14.host AS host - , subq_14.booking__listing AS booking__listing - , subq_14.booking__guest AS booking__guest - , subq_14.booking__host AS booking__host - , subq_14.is_instant AS is_instant - , subq_14.booking__is_instant AS booking__is_instant - , subq_14.bookings AS bookings - , subq_14.instant_bookings AS instant_bookings - , subq_14.booking_value AS booking_value - , subq_14.max_booking_value AS max_booking_value - , subq_14.min_booking_value AS min_booking_value - , subq_14.bookers AS bookers - , subq_14.average_booking_value AS average_booking_value - , subq_14.referred_bookings AS referred_bookings - , subq_14.median_booking_value AS median_booking_value - , subq_14.booking_value_p99 AS booking_value_p99 - , subq_14.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_14.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_14.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 + subq_18.country_latest AS listing__country_latest + , subq_15.ds__day AS ds__day + , subq_15.ds__week AS ds__week + , subq_15.ds__month AS ds__month + , subq_15.ds__quarter AS ds__quarter + , subq_15.ds__year AS ds__year + , subq_15.ds__extract_year AS ds__extract_year + , subq_15.ds__extract_quarter AS ds__extract_quarter + , subq_15.ds__extract_month AS ds__extract_month + , subq_15.ds__extract_day AS ds__extract_day + , subq_15.ds__extract_dow AS ds__extract_dow + , subq_15.ds__extract_doy AS ds__extract_doy + , subq_15.ds_partitioned__day AS ds_partitioned__day + , subq_15.ds_partitioned__week AS ds_partitioned__week + , subq_15.ds_partitioned__month AS ds_partitioned__month + , subq_15.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_15.ds_partitioned__year AS ds_partitioned__year + , subq_15.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_15.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_15.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_15.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_15.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_15.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_15.paid_at__day AS paid_at__day + , subq_15.paid_at__week AS paid_at__week + , subq_15.paid_at__month AS paid_at__month + , subq_15.paid_at__quarter AS paid_at__quarter + , subq_15.paid_at__year AS paid_at__year + , subq_15.paid_at__extract_year AS paid_at__extract_year + , subq_15.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_15.paid_at__extract_month AS paid_at__extract_month + , subq_15.paid_at__extract_day AS paid_at__extract_day + , subq_15.paid_at__extract_dow AS paid_at__extract_dow + , subq_15.paid_at__extract_doy AS paid_at__extract_doy + , subq_15.booking__ds__day AS booking__ds__day + , subq_15.booking__ds__week AS booking__ds__week + , subq_15.booking__ds__month AS booking__ds__month + , subq_15.booking__ds__quarter AS booking__ds__quarter + , subq_15.booking__ds__year AS booking__ds__year + , subq_15.booking__ds__extract_year AS booking__ds__extract_year + , subq_15.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_15.booking__ds__extract_month AS booking__ds__extract_month + , subq_15.booking__ds__extract_day AS booking__ds__extract_day + , subq_15.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_15.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_15.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_15.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_15.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_15.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_15.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_15.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_15.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_15.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_15.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_15.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_15.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_15.booking__paid_at__day AS booking__paid_at__day + , subq_15.booking__paid_at__week AS booking__paid_at__week + , subq_15.booking__paid_at__month AS booking__paid_at__month + , subq_15.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_15.booking__paid_at__year AS booking__paid_at__year + , subq_15.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_15.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_15.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_15.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_15.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_15.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_15.metric_time__week AS metric_time__week + , subq_15.metric_time__month AS metric_time__month + , subq_15.metric_time__quarter AS metric_time__quarter + , subq_15.metric_time__year AS metric_time__year + , subq_15.metric_time__extract_year AS metric_time__extract_year + , subq_15.metric_time__extract_quarter AS metric_time__extract_quarter + , subq_15.metric_time__extract_month AS metric_time__extract_month + , subq_15.metric_time__extract_day AS metric_time__extract_day + , subq_15.metric_time__extract_dow AS metric_time__extract_dow + , subq_15.metric_time__extract_doy AS metric_time__extract_doy + , subq_15.metric_time__day AS metric_time__day + , subq_15.listing AS listing + , subq_15.guest AS guest + , subq_15.host AS host + , subq_15.booking__listing AS booking__listing + , subq_15.booking__guest AS booking__guest + , subq_15.booking__host AS booking__host + , subq_15.is_instant AS is_instant + , subq_15.booking__is_instant AS booking__is_instant + , subq_15.bookings AS bookings + , subq_15.instant_bookings AS instant_bookings + , subq_15.booking_value AS booking_value + , subq_15.max_booking_value AS max_booking_value + , subq_15.min_booking_value AS min_booking_value + , subq_15.bookers AS bookers + , subq_15.average_booking_value AS average_booking_value + , subq_15.referred_bookings AS referred_bookings + , subq_15.median_booking_value AS median_booking_value + , subq_15.booking_value_p99 AS booking_value_p99 + , subq_15.discrete_booking_value_p99 AS discrete_booking_value_p99 + , subq_15.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 + , subq_15.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 FROM ( -- Join to Time Spine Dataset SELECT @@ -885,7 +885,7 @@ FROM ( , subq_11.metric_time__extract_day AS metric_time__extract_day , subq_11.metric_time__extract_dow AS metric_time__extract_dow , subq_11.metric_time__extract_doy AS metric_time__extract_doy - , subq_12.metric_time__day AS metric_time__day + , subq_14.metric_time__day AS metric_time__day , subq_11.listing AS listing , subq_11.guest AS guest , subq_11.host AS host @@ -908,11 +908,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_12.ds__day AS metric_time__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__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_12 + ) subq_13 + ) subq_14 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -1109,83 +1141,83 @@ FROM ( ) subq_10 ) subq_11 ON - subq_12.metric_time__day - INTERVAL 14 day = subq_11.metric_time__day - ) subq_14 + subq_14.metric_time__day - INTERVAL 14 day = subq_11.metric_time__day + ) subq_15 LEFT OUTER JOIN ( -- Pass Only Elements: ['country_latest', 'listing'] SELECT - subq_16.listing - , subq_16.country_latest + subq_17.listing + , subq_17.country_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_15.ds__day - , subq_15.ds__week - , subq_15.ds__month - , subq_15.ds__quarter - , subq_15.ds__year - , subq_15.ds__extract_year - , subq_15.ds__extract_quarter - , subq_15.ds__extract_month - , subq_15.ds__extract_day - , subq_15.ds__extract_dow - , subq_15.ds__extract_doy - , subq_15.created_at__day - , subq_15.created_at__week - , subq_15.created_at__month - , subq_15.created_at__quarter - , subq_15.created_at__year - , subq_15.created_at__extract_year - , subq_15.created_at__extract_quarter - , subq_15.created_at__extract_month - , subq_15.created_at__extract_day - , subq_15.created_at__extract_dow - , subq_15.created_at__extract_doy - , subq_15.listing__ds__day - , subq_15.listing__ds__week - , subq_15.listing__ds__month - , subq_15.listing__ds__quarter - , subq_15.listing__ds__year - , subq_15.listing__ds__extract_year - , subq_15.listing__ds__extract_quarter - , subq_15.listing__ds__extract_month - , subq_15.listing__ds__extract_day - , subq_15.listing__ds__extract_dow - , subq_15.listing__ds__extract_doy - , subq_15.listing__created_at__day - , subq_15.listing__created_at__week - , subq_15.listing__created_at__month - , subq_15.listing__created_at__quarter - , subq_15.listing__created_at__year - , subq_15.listing__created_at__extract_year - , subq_15.listing__created_at__extract_quarter - , subq_15.listing__created_at__extract_month - , subq_15.listing__created_at__extract_day - , subq_15.listing__created_at__extract_dow - , subq_15.listing__created_at__extract_doy - , subq_15.ds__day AS metric_time__day - , subq_15.ds__week AS metric_time__week - , subq_15.ds__month AS metric_time__month - , subq_15.ds__quarter AS metric_time__quarter - , subq_15.ds__year AS metric_time__year - , subq_15.ds__extract_year AS metric_time__extract_year - , subq_15.ds__extract_quarter AS metric_time__extract_quarter - , subq_15.ds__extract_month AS metric_time__extract_month - , subq_15.ds__extract_day AS metric_time__extract_day - , subq_15.ds__extract_dow AS metric_time__extract_dow - , subq_15.ds__extract_doy AS metric_time__extract_doy - , subq_15.listing - , subq_15.user - , subq_15.listing__user - , subq_15.country_latest - , subq_15.is_lux_latest - , subq_15.capacity_latest - , subq_15.listing__country_latest - , subq_15.listing__is_lux_latest - , subq_15.listing__capacity_latest - , subq_15.listings - , subq_15.largest_listing - , subq_15.smallest_listing + subq_16.ds__day + , subq_16.ds__week + , subq_16.ds__month + , subq_16.ds__quarter + , subq_16.ds__year + , subq_16.ds__extract_year + , subq_16.ds__extract_quarter + , subq_16.ds__extract_month + , subq_16.ds__extract_day + , subq_16.ds__extract_dow + , subq_16.ds__extract_doy + , subq_16.created_at__day + , subq_16.created_at__week + , subq_16.created_at__month + , subq_16.created_at__quarter + , subq_16.created_at__year + , subq_16.created_at__extract_year + , subq_16.created_at__extract_quarter + , subq_16.created_at__extract_month + , subq_16.created_at__extract_day + , subq_16.created_at__extract_dow + , subq_16.created_at__extract_doy + , subq_16.listing__ds__day + , subq_16.listing__ds__week + , subq_16.listing__ds__month + , subq_16.listing__ds__quarter + , subq_16.listing__ds__year + , subq_16.listing__ds__extract_year + , subq_16.listing__ds__extract_quarter + , subq_16.listing__ds__extract_month + , subq_16.listing__ds__extract_day + , subq_16.listing__ds__extract_dow + , subq_16.listing__ds__extract_doy + , subq_16.listing__created_at__day + , subq_16.listing__created_at__week + , subq_16.listing__created_at__month + , subq_16.listing__created_at__quarter + , subq_16.listing__created_at__year + , subq_16.listing__created_at__extract_year + , subq_16.listing__created_at__extract_quarter + , subq_16.listing__created_at__extract_month + , subq_16.listing__created_at__extract_day + , subq_16.listing__created_at__extract_dow + , subq_16.listing__created_at__extract_doy + , subq_16.ds__day AS metric_time__day + , subq_16.ds__week AS metric_time__week + , subq_16.ds__month AS metric_time__month + , subq_16.ds__quarter AS metric_time__quarter + , subq_16.ds__year AS metric_time__year + , subq_16.ds__extract_year AS metric_time__extract_year + , subq_16.ds__extract_quarter AS metric_time__extract_quarter + , subq_16.ds__extract_month AS metric_time__extract_month + , subq_16.ds__extract_day AS metric_time__extract_day + , subq_16.ds__extract_dow AS metric_time__extract_dow + , subq_16.ds__extract_doy AS metric_time__extract_doy + , subq_16.listing + , subq_16.user + , subq_16.listing__user + , subq_16.country_latest + , subq_16.is_lux_latest + , subq_16.capacity_latest + , subq_16.listing__country_latest + , subq_16.listing__is_lux_latest + , subq_16.listing__capacity_latest + , subq_16.listings + , subq_16.largest_listing + , subq_16.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -1246,27 +1278,27 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_15 - ) subq_16 - ) subq_17 + ) subq_16 + ) subq_17 + ) subq_18 ON - subq_14.listing = subq_17.listing - ) subq_18 + subq_15.listing = subq_18.listing + ) subq_19 WHERE booking__is_instant - ) subq_19 - ) subq_20 + ) subq_20 + ) subq_21 GROUP BY - subq_20.metric_time__day - , subq_20.listing__country_latest - ) subq_21 - ) subq_22 + subq_21.metric_time__day + , subq_21.listing__country_latest + ) subq_22 + ) subq_23 ON ( - subq_9.listing__country_latest = subq_22.listing__country_latest + subq_9.listing__country_latest = subq_23.listing__country_latest ) AND ( - subq_9.metric_time__day = subq_22.metric_time__day + subq_9.metric_time__day = subq_23.metric_time__day ) GROUP BY - COALESCE(subq_9.metric_time__day, subq_22.metric_time__day) - , COALESCE(subq_9.listing__country_latest, subq_22.listing__country_latest) -) subq_23 + COALESCE(subq_9.metric_time__day, subq_23.metric_time__day) + , COALESCE(subq_9.listing__country_latest, subq_23.listing__country_latest) +) subq_24 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql index ceb090f744..8d0b761341 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_offset_metric_with_query_time_filters__plan0_optimized.sql @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) AS metric_time__day - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) AS listing__country_latest - , MAX(subq_33.bookings) AS bookings - , MAX(subq_44.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) AS metric_time__day + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) AS listing__country_latest + , MAX(subq_34.bookings) AS bookings + , MAX(subq_46.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -59,12 +59,12 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_29 + ) 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'] @@ -78,39 +78,39 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_37.metric_time__day AS metric_time__day - , subq_37.booking__is_instant AS booking__is_instant - , subq_37.bookings AS bookings + , subq_39.metric_time__day AS metric_time__day + , subq_39.booking__is_instant AS booking__is_instant + , subq_39.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_36.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_36 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_36.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day - ) subq_37 + time_spine_src_28006.ds - INTERVAL 14 day = sma_28009_cte.metric_time__day + ) subq_39 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_37.listing = sma_28014_cte.listing - ) subq_40 + subq_39.listing = sma_28014_cte.listing + ) subq_42 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_44 + ) subq_46 ON ( - subq_33.listing__country_latest = subq_44.listing__country_latest + subq_34.listing__country_latest = subq_46.listing__country_latest ) AND ( - subq_33.metric_time__day = subq_44.metric_time__day + subq_34.metric_time__day = subq_46.metric_time__day ) GROUP BY - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) -) subq_45 + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) +) subq_47 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql index 6a063e32fc..6f3912a0f2 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0.sql @@ -8,27 +8,59 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.booking__is_instant - , subq_8.bookings AS bookings_join_to_time_spine + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings AS bookings_join_to_time_spine FROM ( -- Constrain Output with WHERE SELECT - subq_7.metric_time__day - , subq_7.booking__is_instant - , subq_7.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_7.metric_time__day AS metric_time__day , subq_4.booking__is_instant AS booking__is_instant , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -345,7 +377,7 @@ FROM ( , subq_3.booking__is_instant ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_7.metric_time__day = subq_4.metric_time__day + ) subq_8 WHERE booking__is_instant -) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql index c5ff38a66d..8ca9901dab 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_pushdown_filter_application__plan0_optimized.sql @@ -15,10 +15,10 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_15.ds AS metric_time__day - , subq_13.booking__is_instant AS booking__is_instant - , subq_13.bookings AS bookings - FROM ***************************.mf_time_spine subq_15 + time_spine_src_28006.ds AS metric_time__day + , subq_14.booking__is_instant AS booking__is_instant + , subq_14.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -35,13 +35,13 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_14 ON - subq_15.ds = subq_13.metric_time__day -) subq_16 + time_spine_src_28006.ds = subq_14.metric_time__day +) subq_18 WHERE booking__is_instant diff --git a/tests_metricflow/snapshots/test_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 45d6227836..9d053d3722 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,66 @@ 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 ( + -- Change Column Aliases + SELECT + subq_9.ds__day AS metric_time__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__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_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -596,451 +628,515 @@ 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 ( + -- Change Column Aliases + SELECT + subq_27.ds__day AS metric_time__day + , subq_27.ds__week + , subq_27.ds__month + , subq_27.ds__quarter + , subq_27.ds__year + , subq_27.ds__extract_year + , subq_27.ds__extract_quarter + , subq_27.ds__extract_month + , subq_27.ds__extract_day + , subq_27.ds__extract_dow + , subq_27.ds__extract_doy + , subq_27.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_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 ( + -- Change Column Aliases + SELECT + subq_16.ds__day AS metric_time__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.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_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 +1229,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 +1369,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 a168eaed7b..0ae100186f 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) AS metric_time__day - , COALESCE(subq_42.listing__country_latest, subq_56.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_56.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) AS metric_time__day + , COALESCE(subq_46.listing__country_latest, subq_62.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_62.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -47,10 +47,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'] @@ -71,16 +71,16 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_35 + ) 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 @@ -90,10 +90,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_54.ds AS metric_time__day - , subq_52.listing__country_latest AS listing__country_latest - , subq_52.bookings AS bookings - FROM ***************************.mf_time_spine subq_54 + time_spine_src_28006.ds AS metric_time__day + , subq_57.listing__country_latest AS listing__country_latest + , subq_57.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -106,43 +106,43 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_46.metric_time__day AS metric_time__day - , subq_46.booking__is_instant AS booking__is_instant - , subq_46.bookings AS bookings + , subq_51.metric_time__day AS metric_time__day + , subq_51.booking__is_instant AS booking__is_instant + , subq_51.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_45.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_45 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_45.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day - ) subq_46 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day + ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_46.listing = sma_28014_cte.listing - ) subq_49 + subq_51.listing = sma_28014_cte.listing + ) subq_54 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_52 + ) subq_57 ON - subq_54.ds = subq_52.metric_time__day - ) subq_55 - ) subq_56 + time_spine_src_28006.ds = subq_57.metric_time__day + ) subq_61 + ) subq_62 ON ( - subq_42.listing__country_latest = subq_56.listing__country_latest + subq_46.listing__country_latest = subq_62.listing__country_latest ) AND ( - subq_42.metric_time__day = subq_56.metric_time__day + subq_46.metric_time__day = subq_62.metric_time__day ) GROUP BY - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) - , COALESCE(subq_42.listing__country_latest, subq_56.listing__country_latest) -) subq_57 + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) + , COALESCE(subq_46.listing__country_latest, subq_62.listing__country_latest) +) subq_63 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 e2943612fa..a85ed08060 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_12.ds__day AS metric_time__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__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_12 + ) subq_13 + ) subq_14 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -1109,83 +1141,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 +1278,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 fe14fb99c1..9b5025e763 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) AS metric_time__day - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) AS listing__country_latest - , MAX(subq_33.bookings) AS bookings - , MAX(subq_44.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) AS metric_time__day + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) AS listing__country_latest + , MAX(subq_34.bookings) AS bookings + , MAX(subq_46.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -59,12 +59,12 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_29 + ) 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'] @@ -78,39 +78,39 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_37.metric_time__day AS metric_time__day - , subq_37.booking__is_instant AS booking__is_instant - , subq_37.bookings AS bookings + , subq_39.metric_time__day AS metric_time__day + , subq_39.booking__is_instant AS booking__is_instant + , subq_39.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_36.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_36 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - subq_36.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day - ) subq_37 + time_spine_src_28006.ds - MAKE_INTERVAL(days => 14) = sma_28009_cte.metric_time__day + ) subq_39 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_37.listing = sma_28014_cte.listing - ) subq_40 + subq_39.listing = sma_28014_cte.listing + ) subq_42 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_44 + ) subq_46 ON ( - subq_33.listing__country_latest = subq_44.listing__country_latest + subq_34.listing__country_latest = subq_46.listing__country_latest ) AND ( - subq_33.metric_time__day = subq_44.metric_time__day + subq_34.metric_time__day = subq_46.metric_time__day ) GROUP BY - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) -) subq_45 + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) +) subq_47 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 d357c66ea0..3d9ba574c4 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -345,7 +377,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 8b30ca56e5..52dd1020a8 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 5cd70913b4..63c3b7155f 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,66 @@ 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 ( + -- Change Column Aliases + SELECT + subq_9.ds__day AS metric_time__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__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_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -596,451 +628,515 @@ 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 ( + -- Change Column Aliases + SELECT + subq_27.ds__day AS metric_time__day + , subq_27.ds__week + , subq_27.ds__month + , subq_27.ds__quarter + , subq_27.ds__year + , subq_27.ds__extract_year + , subq_27.ds__extract_quarter + , subq_27.ds__extract_month + , subq_27.ds__extract_day + , subq_27.ds__extract_dow + , subq_27.ds__extract_doy + , subq_27.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_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 ( + -- Change Column Aliases + SELECT + subq_16.ds__day AS metric_time__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.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_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 +1229,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 +1369,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 33bf9c6ee8..321d4f55da 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) AS metric_time__day - , COALESCE(subq_42.listing__country_latest, subq_56.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_56.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) AS metric_time__day + , COALESCE(subq_46.listing__country_latest, subq_62.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_62.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -47,10 +47,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'] @@ -71,16 +71,16 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_35 + ) 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 @@ -90,10 +90,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_54.ds AS metric_time__day - , subq_52.listing__country_latest AS listing__country_latest - , subq_52.bookings AS bookings - FROM ***************************.mf_time_spine subq_54 + time_spine_src_28006.ds AS metric_time__day + , subq_57.listing__country_latest AS listing__country_latest + , subq_57.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -106,43 +106,43 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_46.metric_time__day AS metric_time__day - , subq_46.booking__is_instant AS booking__is_instant - , subq_46.bookings AS bookings + , subq_51.metric_time__day AS metric_time__day + , subq_51.booking__is_instant AS booking__is_instant + , subq_51.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_45.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_45 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_45.ds) = sma_28009_cte.metric_time__day - ) subq_46 + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_46.listing = sma_28014_cte.listing - ) subq_49 + subq_51.listing = sma_28014_cte.listing + ) subq_54 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_52 + ) subq_57 ON - subq_54.ds = subq_52.metric_time__day - ) subq_55 - ) subq_56 + time_spine_src_28006.ds = subq_57.metric_time__day + ) subq_61 + ) subq_62 ON ( - subq_42.listing__country_latest = subq_56.listing__country_latest + subq_46.listing__country_latest = subq_62.listing__country_latest ) AND ( - subq_42.metric_time__day = subq_56.metric_time__day + subq_46.metric_time__day = subq_62.metric_time__day ) GROUP BY - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) - , COALESCE(subq_42.listing__country_latest, subq_56.listing__country_latest) -) subq_57 + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) + , COALESCE(subq_46.listing__country_latest, subq_62.listing__country_latest) +) subq_63 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 86c4b97d3f..bd158226bc 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_12.ds__day AS metric_time__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__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_12 + ) subq_13 + ) subq_14 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -1109,83 +1141,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 +1278,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 bb92c675ed..d2c3bfdd34 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) AS metric_time__day - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) AS listing__country_latest - , MAX(subq_33.bookings) AS bookings - , MAX(subq_44.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) AS metric_time__day + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) AS listing__country_latest + , MAX(subq_34.bookings) AS bookings + , MAX(subq_46.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -59,12 +59,12 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_29 + ) 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'] @@ -78,39 +78,39 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_37.metric_time__day AS metric_time__day - , subq_37.booking__is_instant AS booking__is_instant - , subq_37.bookings AS bookings + , subq_39.metric_time__day AS metric_time__day + , subq_39.booking__is_instant AS booking__is_instant + , subq_39.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_36.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_36 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_36.ds) = sma_28009_cte.metric_time__day - ) subq_37 + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_39 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_37.listing = sma_28014_cte.listing - ) subq_40 + subq_39.listing = sma_28014_cte.listing + ) subq_42 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_44 + ) subq_46 ON ( - subq_33.listing__country_latest = subq_44.listing__country_latest + subq_34.listing__country_latest = subq_46.listing__country_latest ) AND ( - subq_33.metric_time__day = subq_44.metric_time__day + subq_34.metric_time__day = subq_46.metric_time__day ) GROUP BY - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) -) subq_45 + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) +) subq_47 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 1389f1d896..1c297a859a 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -345,7 +377,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 0e86ce90f9..c893fefbc9 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 06d700d003..fb491635c8 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,66 @@ 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 ( + -- Change Column Aliases + SELECT + subq_9.ds__day AS metric_time__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__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_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -596,451 +628,515 @@ 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 ( + -- Change Column Aliases + SELECT + subq_27.ds__day AS metric_time__day + , subq_27.ds__week + , subq_27.ds__month + , subq_27.ds__quarter + , subq_27.ds__year + , subq_27.ds__extract_year + , subq_27.ds__extract_quarter + , subq_27.ds__extract_month + , subq_27.ds__extract_day + , subq_27.ds__extract_dow + , subq_27.ds__extract_doy + , subq_27.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_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 ( + -- Change Column Aliases + SELECT + subq_16.ds__day AS metric_time__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.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_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 +1229,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 +1369,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 7ed52650ab..a9bbc330cc 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) AS metric_time__day - , COALESCE(subq_42.listing__country_latest, subq_56.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_56.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) AS metric_time__day + , COALESCE(subq_46.listing__country_latest, subq_62.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_62.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -47,10 +47,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'] @@ -71,16 +71,16 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_35 + ) 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 @@ -90,10 +90,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_54.ds AS metric_time__day - , subq_52.listing__country_latest AS listing__country_latest - , subq_52.bookings AS bookings - FROM ***************************.mf_time_spine subq_54 + time_spine_src_28006.ds AS metric_time__day + , subq_57.listing__country_latest AS listing__country_latest + , subq_57.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -106,43 +106,43 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_46.metric_time__day AS metric_time__day - , subq_46.booking__is_instant AS booking__is_instant - , subq_46.bookings AS bookings + , subq_51.metric_time__day AS metric_time__day + , subq_51.booking__is_instant AS booking__is_instant + , subq_51.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_45.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_45 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_45.ds) = sma_28009_cte.metric_time__day - ) subq_46 + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_46.listing = sma_28014_cte.listing - ) subq_49 + subq_51.listing = sma_28014_cte.listing + ) subq_54 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_52 + ) subq_57 ON - subq_54.ds = subq_52.metric_time__day - ) subq_55 - ) subq_56 + time_spine_src_28006.ds = subq_57.metric_time__day + ) subq_61 + ) subq_62 ON ( - subq_42.listing__country_latest = subq_56.listing__country_latest + subq_46.listing__country_latest = subq_62.listing__country_latest ) AND ( - subq_42.metric_time__day = subq_56.metric_time__day + subq_46.metric_time__day = subq_62.metric_time__day ) GROUP BY - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) - , COALESCE(subq_42.listing__country_latest, subq_56.listing__country_latest) -) subq_57 + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) + , COALESCE(subq_46.listing__country_latest, subq_62.listing__country_latest) +) subq_63 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 58096f0e8a..9193aad9da 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_12.ds__day AS metric_time__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__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_12 + ) subq_13 + ) subq_14 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -1109,83 +1141,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 +1278,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 170de6c318..8204d805c5 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) AS metric_time__day - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) AS listing__country_latest - , MAX(subq_33.bookings) AS bookings - , MAX(subq_44.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) AS metric_time__day + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) AS listing__country_latest + , MAX(subq_34.bookings) AS bookings + , MAX(subq_46.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -59,12 +59,12 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_29 + ) 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'] @@ -78,39 +78,39 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_37.metric_time__day AS metric_time__day - , subq_37.booking__is_instant AS booking__is_instant - , subq_37.bookings AS bookings + , subq_39.metric_time__day AS metric_time__day + , subq_39.booking__is_instant AS booking__is_instant + , subq_39.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_36.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_36 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATEADD(day, -14, subq_36.ds) = sma_28009_cte.metric_time__day - ) subq_37 + DATEADD(day, -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_39 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_37.listing = sma_28014_cte.listing - ) subq_40 + subq_39.listing = sma_28014_cte.listing + ) subq_42 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_44 + ) subq_46 ON ( - subq_33.listing__country_latest = subq_44.listing__country_latest + subq_34.listing__country_latest = subq_46.listing__country_latest ) AND ( - subq_33.metric_time__day = subq_44.metric_time__day + subq_34.metric_time__day = subq_46.metric_time__day ) GROUP BY - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) -) subq_45 + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) +) subq_47 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 8af26b0e96..14fca44e7d 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -345,7 +377,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 9abfe0b08d..b9adcba9fa 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 f43548aff4..bd8f31df9a 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,66 @@ 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 ( + -- Change Column Aliases + SELECT + subq_9.ds__day AS metric_time__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__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_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -596,451 +628,515 @@ 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 ( + -- Change Column Aliases + SELECT + subq_27.ds__day AS metric_time__day + , subq_27.ds__week + , subq_27.ds__month + , subq_27.ds__quarter + , subq_27.ds__year + , subq_27.ds__extract_year + , subq_27.ds__extract_quarter + , subq_27.ds__extract_month + , subq_27.ds__extract_day + , subq_27.ds__extract_dow + , subq_27.ds__extract_doy + , subq_27.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_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 ( + -- Change Column Aliases + SELECT + subq_16.ds__day AS metric_time__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.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_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 +1229,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 +1369,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 a42c11163b..ff3f3308e9 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) AS metric_time__day - , COALESCE(subq_42.listing__country_latest, subq_56.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_56.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) AS metric_time__day + , COALESCE(subq_46.listing__country_latest, subq_62.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_62.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -47,10 +47,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'] @@ -71,16 +71,16 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_35 + ) 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 @@ -90,10 +90,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_54.ds AS metric_time__day - , subq_52.listing__country_latest AS listing__country_latest - , subq_52.bookings AS bookings - FROM ***************************.mf_time_spine subq_54 + time_spine_src_28006.ds AS metric_time__day + , subq_57.listing__country_latest AS listing__country_latest + , subq_57.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -106,43 +106,43 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_46.metric_time__day AS metric_time__day - , subq_46.booking__is_instant AS booking__is_instant - , subq_46.bookings AS bookings + , subq_51.metric_time__day AS metric_time__day + , subq_51.booking__is_instant AS booking__is_instant + , subq_51.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_45.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_45 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('day', -14, subq_45.ds) = sma_28009_cte.metric_time__day - ) subq_46 + DATE_ADD('day', -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_51 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_46.listing = sma_28014_cte.listing - ) subq_49 + subq_51.listing = sma_28014_cte.listing + ) subq_54 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_52 + ) subq_57 ON - subq_54.ds = subq_52.metric_time__day - ) subq_55 - ) subq_56 + time_spine_src_28006.ds = subq_57.metric_time__day + ) subq_61 + ) subq_62 ON ( - subq_42.listing__country_latest = subq_56.listing__country_latest + subq_46.listing__country_latest = subq_62.listing__country_latest ) AND ( - subq_42.metric_time__day = subq_56.metric_time__day + subq_46.metric_time__day = subq_62.metric_time__day ) GROUP BY - COALESCE(subq_42.metric_time__day, subq_56.metric_time__day) - , COALESCE(subq_42.listing__country_latest, subq_56.listing__country_latest) -) subq_57 + COALESCE(subq_46.metric_time__day, subq_62.metric_time__day) + , COALESCE(subq_46.listing__country_latest, subq_62.listing__country_latest) +) subq_63 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 a0e2d67c17..e85e67162c 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,43 @@ 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 ( + -- Change Column Aliases + SELECT + subq_12.ds__day AS metric_time__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__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_12 + ) subq_13 + ) subq_14 INNER JOIN ( -- Metric Time Dimension 'ds' SELECT @@ -1109,83 +1141,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 +1278,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 e4101cd297..bb9a42bcc8 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 @@ -34,10 +34,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) AS metric_time__day - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) AS listing__country_latest - , MAX(subq_33.bookings) AS bookings - , MAX(subq_44.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) AS metric_time__day + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) AS listing__country_latest + , MAX(subq_34.bookings) AS bookings + , MAX(subq_46.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -59,12 +59,12 @@ FROM ( sma_28014_cte sma_28014_cte ON sma_28009_cte.listing = sma_28014_cte.listing - ) subq_29 + ) 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'] @@ -78,39 +78,39 @@ FROM ( -- Join Standard Outputs SELECT sma_28014_cte.country_latest AS listing__country_latest - , subq_37.metric_time__day AS metric_time__day - , subq_37.booking__is_instant AS booking__is_instant - , subq_37.bookings AS bookings + , subq_39.metric_time__day AS metric_time__day + , subq_39.booking__is_instant AS booking__is_instant + , subq_39.bookings AS bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_36.ds AS metric_time__day + time_spine_src_28006.ds AS metric_time__day , sma_28009_cte.listing AS listing , sma_28009_cte.booking__is_instant AS booking__is_instant , sma_28009_cte.bookings AS bookings - FROM ***************************.mf_time_spine subq_36 + FROM ***************************.mf_time_spine time_spine_src_28006 INNER JOIN sma_28009_cte sma_28009_cte ON - DATE_ADD('day', -14, subq_36.ds) = sma_28009_cte.metric_time__day - ) subq_37 + DATE_ADD('day', -14, time_spine_src_28006.ds) = sma_28009_cte.metric_time__day + ) subq_39 LEFT OUTER JOIN sma_28014_cte sma_28014_cte ON - subq_37.listing = sma_28014_cte.listing - ) subq_40 + subq_39.listing = sma_28014_cte.listing + ) subq_42 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_44 + ) subq_46 ON ( - subq_33.listing__country_latest = subq_44.listing__country_latest + subq_34.listing__country_latest = subq_46.listing__country_latest ) AND ( - subq_33.metric_time__day = subq_44.metric_time__day + subq_34.metric_time__day = subq_46.metric_time__day ) GROUP BY - COALESCE(subq_33.metric_time__day, subq_44.metric_time__day) - , COALESCE(subq_33.listing__country_latest, subq_44.listing__country_latest) -) subq_45 + COALESCE(subq_34.metric_time__day, subq_46.metric_time__day) + , COALESCE(subq_34.listing__country_latest, subq_46.listing__country_latest) +) subq_47 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 aeb65f982c..76d4c88286 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -345,7 +377,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 cc5b200f41..acd93ba336 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_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 618a056455..1df5f45cc6 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,70 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +388,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 85b20c5d7c..6ae84e6b2f 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' + -- Change Column Aliases 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 06bdf58c3a..6a875e67f6 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,73 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +386,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 de3aa30c2b..b46601e561 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' + -- Change Column Aliases + -- 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 f4b12a8d77..9e53ac1831 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 dc9cd55117..a9f0e04cf4 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 999f6c319b..fd9fc95287 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -332,5 +364,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 c76f36ad90..1f7a1824dd 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 364344f673..640e7629c6 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -343,7 +375,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 4bb4638cfb..e7f02ec47a 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 cd5b0f7415..114757a39f 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,70 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +388,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 5990d18b17..44df49e286 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' + -- Change Column Aliases 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 2309540a01..8a75fa0e60 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,73 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +386,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 399086d226..7a97dc685c 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' + -- Change Column Aliases + -- 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 8d1dba903a..1e595dadfe 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 e3aff697e8..375262c7f9 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 cf0e7eb665..6d591f1d2c 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -332,5 +364,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 dc1e54c55b..b1b4d38fab 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 e7188d22d5..7192e9886b 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -343,7 +375,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 3db4958ce9..e4cd9eaee3 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/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql index 82c85e9bd4..35c4688bc3 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0.sql @@ -8,27 +8,70 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.booking__is_instant - , subq_8.bookings AS instant_bookings_with_measure_filter + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings AS instant_bookings_with_measure_filter FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.booking__is_instant AS booking__is_instant , subq_4.bookings AS bookings FROM ( - -- Filter Time Spine + -- Pass Only Elements: ['metric_time__day',] SELECT subq_7.metric_time__day FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Constrain Output with WHERE SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 + subq_6.ds__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +388,5 @@ FROM ( , subq_3.booking__is_instant ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day +) subq_9 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql index 12b8e97468..155eae2d42 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_input_measure_constraint__plan0_optimized.sql @@ -9,21 +9,23 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.booking__is_instant AS booking__is_instant - , subq_13.bookings AS instant_bookings_with_measure_filter + subq_18.metric_time__day AS metric_time__day + , subq_14.booking__is_instant AS booking__is_instant + , subq_14.bookings AS instant_bookings_with_measure_filter FROM ( - -- Filter Time Spine + -- Constrain Output with WHERE + -- Pass Only Elements: ['metric_time__day',] SELECT metric_time__day FROM ( -- Read From Time Spine 'mf_time_spine' + -- Change Column Aliases SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 ) subq_16 WHERE metric_time__day > '2020-01-01' -) subq_14 +) subq_18 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -41,11 +43,11 @@ LEFT OUTER JOIN ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE ((booking__is_instant) AND (listing IS NOT NULL)) AND (metric_time__day > '2020-01-01') GROUP BY metric_time__day , booking__is_instant -) subq_13 +) subq_14 ON - subq_14.metric_time__day = subq_13.metric_time__day + subq_18.metric_time__day = subq_14.metric_time__day diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql index 2ce1521c99..29b5b38422 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0.sql @@ -6,25 +6,73 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_10.metric_time__day + , COALESCE(subq_10.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_7.metric_time__day - , subq_7.bookings + subq_9.metric_time__day + , subq_9.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_8.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - WHERE subq_6.ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_5 + subq_7.metric_time__day + FROM ( + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + SELECT + subq_6.ds__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +386,7 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 - WHERE subq_7.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_8 + subq_8.metric_time__day = subq_4.metric_time__day + ) subq_9 + WHERE subq_9.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_10 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql index 6e1385158a..b77e3140dd 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_with_queried_time_constraint__plan0_optimized.sql @@ -12,15 +12,18 @@ FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_14.metric_time__day AS metric_time__day - , subq_13.bookings AS bookings + subq_19.metric_time__day AS metric_time__day + , subq_15.bookings AS bookings FROM ( -- Read From Time Spine 'mf_time_spine' + -- Change Column Aliases + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + -- Pass Only Elements: ['metric_time__day',] SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine time_spine_src_28006 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_14 + ) subq_19 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -36,11 +39,11 @@ FROM ( , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_12 + ) subq_14 GROUP BY metric_time__day - ) subq_13 + ) subq_15 ON - subq_14.metric_time__day = subq_13.metric_time__day - WHERE subq_14.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_17 + subq_19.metric_time__day = subq_15.metric_time__day + WHERE subq_19.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_21 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql index a916df15a5..8373b2e1ac 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0.sql @@ -4,19 +4,51 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings AS bookings_join_to_time_spine + subq_7.metric_time__day + , subq_7.bookings AS bookings_join_to_time_spine FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day + subq_6.metric_time__day AS metric_time__day , subq_3.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_5.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,5 @@ FROM ( subq_2.metric_time__day ) subq_3 ON - subq_4.metric_time__day = subq_3.metric_time__day -) subq_6 + subq_6.metric_time__day = subq_3.metric_time__day +) subq_7 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql index c8ecb775a6..7be71a09b5 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine__plan0_optimized.sql @@ -5,9 +5,9 @@ sql_engine: DuckDB -- Join to Time Spine Dataset -- Compute Metrics via Expressions SELECT - subq_12.ds AS metric_time__day - , subq_10.bookings AS bookings_join_to_time_spine -FROM ***************************.mf_time_spine subq_12 + time_spine_src_28006.ds AS metric_time__day + , subq_11.bookings AS bookings_join_to_time_spine +FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -21,9 +21,9 @@ LEFT OUTER JOIN ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 GROUP BY metric_time__day -) subq_10 +) subq_11 ON - subq_12.ds = subq_10.metric_time__day + time_spine_src_28006.ds = subq_11.metric_time__day diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql index 67dfb9f894..25f0fac727 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql @@ -6,19 +6,51 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , COALESCE(subq_7.bookings, 0) AS bookings_fill_nulls_with_0 + subq_8.metric_time__day + , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_7.metric_time__day AS metric_time__day , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -332,5 +364,5 @@ FROM ( subq_3.metric_time__day ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day -) subq_7 + subq_7.metric_time__day = subq_4.metric_time__day +) subq_8 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql index 8a474a7060..58b71e0dc5 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql @@ -11,9 +11,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_14.ds AS metric_time__day - , subq_12.bookings AS bookings - FROM ***************************.mf_time_spine subq_14 + time_spine_src_28006.ds AS metric_time__day + , subq_13.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -29,11 +29,11 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_10 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_12 + ) subq_13 ON - subq_14.ds = subq_12.metric_time__day -) subq_15 + time_spine_src_28006.ds = subq_13.metric_time__day +) subq_17 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index 37c2eb64f5..78fa8c8831 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql @@ -6,27 +6,59 @@ sql_engine: DuckDB --- -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.booking__is_instant - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_9.metric_time__day + , subq_9.booking__is_instant + , COALESCE(subq_9.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Constrain Output with WHERE SELECT - subq_7.metric_time__day - , subq_7.booking__is_instant - , subq_7.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day + subq_7.metric_time__day AS metric_time__day , subq_4.booking__is_instant AS booking__is_instant , subq_4.bookings AS bookings FROM ( - -- Read From Time Spine 'mf_time_spine' + -- Pass Only Elements: ['metric_time__day',] SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -343,7 +375,7 @@ FROM ( , subq_3.booking__is_instant ) subq_4 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_7.metric_time__day = subq_4.metric_time__day + ) subq_8 WHERE booking__is_instant -) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql index 6a3d97a372..473dd7f259 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql @@ -18,10 +18,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_15.ds AS metric_time__day - , subq_13.booking__is_instant AS booking__is_instant - , subq_13.bookings AS bookings - FROM ***************************.mf_time_spine subq_15 + time_spine_src_28006.ds AS metric_time__day + , subq_14.booking__is_instant AS booking__is_instant + , subq_14.bookings AS bookings + FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] @@ -38,14 +38,14 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_11 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_14 ON - subq_15.ds = subq_13.metric_time__day - ) subq_16 + time_spine_src_28006.ds = subq_14.metric_time__day + ) subq_18 WHERE booking__is_instant -) subq_17 +) subq_19 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 b0cb402f51..920de60edb 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,70 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +388,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 e321608335..747b137adf 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' + -- Change Column Aliases 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 e793ec07bb..c54ea7faa8 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,73 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +386,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 d1a6367966..74eeac9fa0 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' + -- Change Column Aliases + -- 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 bbfe367e41..1980c43027 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 b3aab0ff2b..da1a9518f2 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 9c8e16b6b3..1606658406 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -332,5 +364,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 13abbd386f..4b272126d7 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 c546f8d7e5..0161b5187f 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -343,7 +375,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 91bd1ce2c9..68d512f46a 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 655a90ba4a..4cc8afbcc6 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,70 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +388,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 d2225e0934..6a379aa0b4 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' + -- Change Column Aliases 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 91361265f4..ea63630656 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,73 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +386,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 0ac19b1a3d..a67b3cf348 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' + -- Change Column Aliases + -- 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 b9778225fc..c4fbda494b 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 5b0894fa0a..51a8c0406d 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 a9c9317585..09ff287d1d 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -332,5 +364,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 9d727697e0..85a1d5d2e1 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 8c33b63fb3..d0ffbfe281 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -343,7 +375,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 c9793b14c7..849c390994 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 ee3f16a50d..7d5fda79f5 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,70 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +388,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 98954f84bf..a3b59f4f73 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' + -- Change Column Aliases 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 1f0e70a8be..e193fcfa02 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,73 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +386,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 331e97ac60..0de73f53fc 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' + -- Change Column Aliases + -- 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 2fe7ef70cd..fc0e2bc8f8 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 7819cc490d..c384955899 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 88e372e4b2..e8ba60d77c 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -332,5 +364,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 7f6e67f0db..7b68820464 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 1f44f6f733..760a689b4a 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -343,7 +375,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 b2a37384b6..704c378706 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 4dd7001fd6..ddd426a606 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,70 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +388,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 98b9811d20..d9bdc1f40e 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' + -- Change Column Aliases 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 5d71cfc2ea..01c381f014 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,73 @@ 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__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__martian_day + , subq_6.metric_time__day + FROM ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + 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 +386,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 ec034f8704..a8fc001f97 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' + -- Change Column Aliases + -- 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 8b2da0017b..e8a4d62a25 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_4.ds__day AS metric_time__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__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_4 + ) subq_5 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -227,5 +259,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 31148d821f..5a3579c4ae 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 baef9e45ff..ae6368af30 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,51 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -332,5 +364,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 f8f5f9dc09..7f85df947c 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 636492a102..759257e45b 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,59 @@ 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 ( + -- Change Column Aliases + SELECT + subq_5.ds__day AS metric_time__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__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 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -343,7 +375,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 fd38b34a28..fadf7d6cb1 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